Struct screeps::RawObjectId [−][src]
Represents an Object ID using a packed 12-byte representation
Each object id in screeps is represented by a Mongo GUID, which, while not guaranteed, is unlikely to change. This takes advantage of that by storing a packed representation.
To convert to a String in JavaScript, either use
RawObjectId::to_array_string
, or RawObjectId::unsafe_as_uploaded
.
See method documentation for more information.
Ordering
To facilitate use as a key in a BTreeMap
or other similar data
structures, ObjectId
implements PartialOrd
and Ord
.
RawObjectId
's are ordered by the corresponding order of their underlying
byte values. See ObjectId
documentation for more information.
Implementations
impl RawObjectId
[src]
pub fn from_packed(packed: [u32; 3]) -> Self
[src]
Creates an object ID from its packed representation.
The input to this function is the bytes representing the up-to-24 hex digits in the object id.
pub fn from_packed_js_val(
packed_val: Reference
) -> Result<Self, ConversionError>
[src]
packed_val: Reference
) -> Result<Self, ConversionError>
Creates an object ID from a packed representation stored in JavaScript.
The input must be a reference to a length-3 array of integers.
Recommended to be used with the object_id_to_packed
JavaScript utility
function, which takes in a string and returns the array of three
integers that this function expects.
Example
use screeps::{prelude::*, traits::TryInto, RawObjectId}; use stdweb::js; let packed_obj_id = (js! { let creep = _.sample(Game.creeps); return object_id_to_packed(creep.id); }) .try_into() .unwrap(); let parsed = RawObjectId::from_packed_js_val(packed_obj_id).unwrap(); println!("found creep with id {}", parsed);
pub fn to_u128(self) -> u128
[src]
Converts this object ID to a u128
number.
The returned number, when formatted as hex, will produce a string parseable into this object id.
The returned number will be less than or equal to 2^96 - 1
, as that's
the maximum value that RawObjectId
can hold.
pub fn to_array_string(&self) -> ArrayString<[u8; 24]>
[src]
Formats this object ID as a string on the stack.
This is equivalent to ToString::to_string
, but involves no
allocation.
To use the produced string in stdweb, use &*
to convert it to a string
slice.
This is less efficient than RawObjectId::unsafe_as_uploaded
, but
easier to get right.
Example
use screeps::{prelude::*, RawObjectId}; use stdweb::js; let object_id: RawObjectId = screeps::game::creeps::values()[0].untyped_id(); let str_repr = object_id.to_array_string(); js! { let id = @{&*str_repr}; console.log("we have a creep with the id " + id); }
pub unsafe fn unsafe_as_uploaded(&self) -> UnsafeTypedArray<'_, u32>
[src]
Creates an array accessible from JavaScript which represents part of this object id's packed representation.
Specifically, the resulting array will contain the first non-zero number
in this object id, and all following numbers. This allows for a more
efficient object_id_from_packed
implementation.
Safety
This is highly unsafe.
This creates an UnsafeTypedArray
and does not use it in JS, so the
restrictions from UnsafeTypedArray
apply. When you call into
JavaScript using it, you must "use" it immediately before calling into
any Rust code whatsoever.
There are other safety concerns as well, but all deriving from
UnsafeTypedArray
. See UnsafeTypedArray
.
Example
use screeps::{prelude::*, RawObjectId}; use stdweb::js; let object_id: RawObjectId = screeps::game::creeps::values()[0].untyped_id(); let array_view = unsafe { object_id.unsafe_as_uploaded() }; js! { let id = object_id_from_packed(@{array_view}); console.log("we have a creep with the id " + id); }
Trait Implementations
impl Clone for RawObjectId
[src]
fn clone(&self) -> RawObjectId
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for RawObjectId
[src]
impl Debug for RawObjectId
[src]
impl<'de> Deserialize<'de> for RawObjectId
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl Display for RawObjectId
[src]
impl Eq for RawObjectId
[src]
impl From<[u32; 3]> for RawObjectId
[src]
impl<T> From<ObjectId<T>> for RawObjectId
[src]
impl<T> From<RawObjectId> for ObjectId<T>
[src]
fn from(raw: RawObjectId) -> Self
[src]
impl FromStr for RawObjectId
[src]
type Err = RawObjectIdParseError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, RawObjectIdParseError>
[src]
impl Hash for RawObjectId
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for RawObjectId
[src]
fn cmp(&self, other: &RawObjectId) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<T> PartialEq<ObjectId<T>> for RawObjectId
[src]
fn eq(&self, other: &ObjectId<T>) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialEq<RawObjectId> for RawObjectId
[src]
fn eq(&self, other: &RawObjectId) -> bool
[src]
fn ne(&self, other: &RawObjectId) -> bool
[src]
impl<T> PartialEq<RawObjectId> for ObjectId<T>
[src]
fn eq(&self, other: &RawObjectId) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<T> PartialOrd<ObjectId<T>> for RawObjectId
[src]
fn partial_cmp(&self, other: &ObjectId<T>) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<RawObjectId> for RawObjectId
[src]
fn partial_cmp(&self, other: &RawObjectId) -> Option<Ordering>
[src]
fn lt(&self, other: &RawObjectId) -> bool
[src]
fn le(&self, other: &RawObjectId) -> bool
[src]
fn gt(&self, other: &RawObjectId) -> bool
[src]
fn ge(&self, other: &RawObjectId) -> bool
[src]
impl<T> PartialOrd<RawObjectId> for ObjectId<T>
[src]
fn partial_cmp(&self, other: &RawObjectId) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl Serialize for RawObjectId
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl StructuralEq for RawObjectId
[src]
impl StructuralPartialEq for RawObjectId
[src]
impl TryFrom<u128> for RawObjectId
[src]
type Error = RawObjectIdParseError
The type returned in the event of a conversion error.
fn try_from(val: u128) -> Result<Self, RawObjectIdParseError>
[src]
Creates an object ID from its binary representation as a u128
number.
Errors
This will error if the given value is greater than 2^96 - 1
, the
maximum number storable in a 96-bit integer.
Auto Trait Implementations
impl RefUnwindSafe for RawObjectId
[src]
impl Send for RawObjectId
[src]
impl Sync for RawObjectId
[src]
impl Unpin for RawObjectId
[src]
impl UnwindSafe for RawObjectId
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> IntoExpectedType<U> for T where
U: FromExpectedType<T>,
[src]
U: FromExpectedType<T>,
pub fn into_expected_type(Self) -> Result<U, ConversionError>
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,