sui_sdk_types/
object_id.rsuse super::Address;
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct ObjectId(Address);
impl ObjectId {
pub const LENGTH: usize = Address::LENGTH;
pub const ZERO: Self = Self(Address::ZERO);
pub const fn new(bytes: [u8; Self::LENGTH]) -> Self {
Self(Address::new(bytes))
}
pub const fn into_inner(self) -> [u8; Self::LENGTH] {
self.0.into_inner()
}
pub const fn inner(&self) -> &[u8; Self::LENGTH] {
self.0.inner()
}
pub const fn as_bytes(&self) -> &[u8] {
self.0.as_bytes()
}
pub const fn as_address(&self) -> &Address {
&self.0
}
}
impl AsRef<[u8]> for ObjectId {
fn as_ref(&self) -> &[u8] {
self.0.as_ref()
}
}
impl AsRef<[u8; 32]> for ObjectId {
fn as_ref(&self) -> &[u8; 32] {
self.0.as_ref()
}
}
impl From<ObjectId> for [u8; 32] {
fn from(object_id: ObjectId) -> Self {
object_id.into_inner()
}
}
impl From<[u8; 32]> for ObjectId {
fn from(object_id: [u8; 32]) -> Self {
Self::new(object_id)
}
}
impl From<Address> for ObjectId {
fn from(value: Address) -> Self {
Self(value)
}
}
impl From<ObjectId> for Vec<u8> {
fn from(value: ObjectId) -> Self {
value.0.into()
}
}
impl std::str::FromStr for ObjectId {
type Err = super::address::AddressParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Address::from_str(s).map(Self)
}
}
impl std::fmt::Display for ObjectId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}