pub enum Rid {
Valid(NonZero<u64>),
Invalid,
}
Expand description
A RID (“resource ID”) is an opaque handle that refers to a Godot Resource
.
RIDs do not grant access to the resource itself. Instead, they can be used in lower-level resource APIs
such as the servers. See also Godot API docs for RID
.
RIDs should be largely safe to work with. Certain calls to servers may fail, however doing so will trigger an error from Godot, and will not cause any UB.
§Safety Caveat:
In Godot 3, RID was not as safe as described here. We believe that this is fixed in Godot 4, but this has not been extensively tested as of yet. Some confirmed UB from Godot 3 does not occur anymore, but if you find anything suspicious or outright UB please open an issue.
Variants§
Valid(NonZero<u64>)
A valid RID may refer to some resource, but is not guaranteed to do so.
Invalid
An invalid RID will never refer to a resource. Internally it is represented as a 0.
Implementations§
§impl Rid
impl Rid
pub const fn to_u64(self) -> u64
pub const fn to_u64(self) -> u64
Convert this RID into a u64
. Returns 0 if it is invalid.
Godot equivalent: Rid.get_id()
pub const fn to_valid_u64(self) -> Option<u64>
pub const fn to_valid_u64(self) -> Option<u64>
Convert this RID into a u64
if it is valid. Otherwise return None.
pub const fn is_invalid(&self) -> bool
pub const fn is_invalid(&self) -> bool
Returns true
if this is an invalid RID.
Trait Implementations§
§impl FromGodot for Rid
impl FromGodot for Rid
§fn try_from_godot(via: <Rid as GodotConvert>::Via) -> Result<Rid, ConvertError>
fn try_from_godot(via: <Rid as GodotConvert>::Via) -> Result<Rid, ConvertError>
§fn from_godot(via: Self::Via) -> Self
fn from_godot(via: Self::Via) -> Self
§fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>
fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>
Variant
.§fn from_variant(variant: &Variant) -> Self
fn from_variant(variant: &Variant) -> Self
§impl Ord for Rid
impl Ord for Rid
§impl PartialOrd for Rid
impl PartialOrd for Rid
§fn partial_cmp(&self, other: &Rid) -> Option<Ordering>
fn partial_cmp(&self, other: &Rid) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more