Skip to main content

Mojo struct

SourceLocation

@register_passable(trivial) struct SourceLocation

Type to carry file name, line, and column information.

Fields

  • line (Int): The line number (1-indexed).
  • col (Int): The column number (1-indexed).
  • file_name (StaticString): The file name.

Implemented traits

AnyType, Copyable, ImplicitlyCopyable, ImplicitlyDestructible, Movable, Stringable, Writable

comptime members

__copyinit__is_trivial

comptime __copyinit__is_trivial = True

__del__is_trivial

comptime __del__is_trivial = True

__moveinit__is_trivial

comptime __moveinit__is_trivial = True

Methods

__str__

__str__(self) -> String

Returns a string representation of the source location.

Returns:

String: A string in the format "file_name:line:col".

prefix

prefix[T: Writable](self, msg: T) -> String

Returns the given message prefixed with the source location.

Parameters:

  • T (Writable): The type of the message.

Args:

  • msg (T): The message to attach the prefix to.

Returns:

String: A string in the format "At file:line:col: msg".

write_to

write_to(self, mut writer: T)

Formats the source location to the provided Writer.

Args:

  • writer (T): The object to write to.

Was this page helpful?