Mojo trait
CommTuningConfig
Implemented traitsβ
AnyType,
Copyable,
ImplicitlyCopyable,
ImplicitlyDestructible,
Movable,
RegisterPassable,
TrivialRegisterPassable,
TuningConfig,
Writable
Required methodsβ
__init__β
__init__(out self: _Self, *, copy: _Self)
Create a new instance of the value by copying an existing one.
Args:
- βcopy (
_Self): The value to copy.
Returns:
_Self
__init__(out self: _Self, *, deinit take: _Self)
Create a new instance of the value by moving the value of another.
Args:
- βtake (
_Self): The value to move.
Returns:
_Self
get_num_blocksβ
get_num_bytesβ
get_sm_versionβ
get_sm_version(self: _Self) -> StaticString
Returns:
StaticString
get_ngpusβ
Provided methodsβ
copyβ
copy(self: _Self) -> _Self
Explicitly construct a copy of self, a convenience method for Self(copy=self) when the type is inconvenient to write out.
Returns:
_Self: A copy of this value.
write_toβ
write_to(self: _Self, mut writer: T)
Write this value's text representation to a writer.
This method is called by print(), String(), and format strings to
convert the value to text. Override this method to define how your type
appears when printed or converted to a string.
The default implementation uses reflection to format all fields as
TypeName(field1=value1, field2=value2, ...), calling write_to()
on each field. All fields must conform to Writable.
Example:
@fieldwise_init
struct Point(Writable):
var x: Float64
var y: Float64
def write_to(self, mut writer: Some[Writer]):
writer.write("(", self.x, ", ", self.y, ")")Args:
- βwriter (
T): The destination for formatted output.
write_repr_toβ
write_repr_to(self: _Self, mut writer: T)
Write this value's debug representation to a writer.
This method is called by repr(value) or the "{!r}" format specifier
and should produce unambiguous, developer-facing output that shows the
internal state of the value.
The default implementation uses reflection to format all fields as
TypeName(field1=value1, field2=value2, ...), calling write_repr_to()
on each field. All fields must conform to Writable.
Example:
@fieldwise_init
struct Point(Writable):
var x: Float64
var y: Float64
def write_repr_to(self, mut writer: Some[Writer]):
writer.write("Point: x=", self.x, ", y=", self.y)Notes:
Mojo's repr always prints single quotes (') at the start and end
of the repr. Any single quote inside a string should be escaped
(\').
Args:
- βwriter (
T): The destination for formatted output.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!