pub struct Id30(/* private fields */);
Expand description
An implementation of the Id30 encoding scheme as documented at the crate root.
This type holds a 30 bit integer as a 32 bit integer, of which the two most
significant bits are always zero. The type has the same representation as
u32
. Debug-formatting includes both the Id30 encoding and the integer
representation.
Ordering, as implemented for the PartialOrd
and Ord
traits, orders by
numerical value of the underlying integer. This is the same order as the
lexicographical ordering of the string representation.
There are many ways to create instances of Id30
:
- Via the
TryFrom
trait from either au32
or ani32
:let id: Id30 = 1234.try_into().expect("1234 is in range"); assert_eq!(Id30::try_from(1 << 31), Err(id30::OutOfRangeError));
- Parsing, via the
FromStr
trait:Tip: Parse to thelet id: id30::Id30 = "hrga2q".parse().unwrap();
Id30Parse
type if you need to know whether the text representation is canonical or alternate. - With feature
rand
, via theDistribution
trait:use rand::{distributions::Standard, prelude::*}; let mut rng = rand::thread_rng(); let id: Id30 = rng.gen(); let ids: Vec<Id30> = Standard.sample_iter(rng).take(10).collect();
- With feature
serde
, via deserialization - With feature
diesel
, as output from queries
An Id30
can be converted directly to u32
and i32
via the From
trait:
let id: Id30 = 1234.try_into().unwrap();
assert_eq!(u32::from(id), 1234);
To generate the text representation:
- format an
Id30
value via theDisplay
trait:let id: id30::Id30 = "j9yceq".parse().unwrap(); assert_eq!(&id.to_string(), "j9yceq"); assert_eq!(&format!("/path/to/{id}"), "/path/to/j9yceq");
- or, with feature
serde
, via serialization
§Integrations with other crates
-
crate
rand
via featurerand08
(aliasrand
):Id30
implementsDistribution
, enabling generation of randomId30
values. -
crate
serde
via featureserde1
(aliasserde
):Id30
implementsSerialize
andDeserialize
, enabling serialization and deserialization ofId30
values as text through serde. -
crate
diesel
via featurediesel2
(aliasdiesel
):Id30
implementsFromSql
andQueryable
, enabling deserialization of integers from the database asId30
values, andToSql
, enabling serialization ofId30
values as integers in the database. Additionally,AsExpression
is implemented, enabling the usage ofId30
values in diesel query builder expressions.
Trait Implementations§
source§impl<'expr> AsExpression<Integer> for &'expr Id30
impl<'expr> AsExpression<Integer> for &'expr Id30
§type Expression = Bound<Integer, &'expr Id30>
type Expression = Bound<Integer, &'expr Id30>
source§fn as_expression(self) -> Self::Expression
fn as_expression(self) -> Self::Expression
source§impl AsExpression<Integer> for Id30
impl AsExpression<Integer> for Id30
§type Expression = Bound<Integer, Id30>
type Expression = Bound<Integer, Id30>
source§fn as_expression(self) -> Self::Expression
fn as_expression(self) -> Self::Expression
source§impl<'expr> AsExpression<Nullable<Integer>> for &'expr Id30
impl<'expr> AsExpression<Nullable<Integer>> for &'expr Id30
§type Expression = Bound<Nullable<Integer>, &'expr Id30>
type Expression = Bound<Nullable<Integer>, &'expr Id30>
source§fn as_expression(self) -> Self::Expression
fn as_expression(self) -> Self::Expression
source§impl AsExpression<Nullable<Integer>> for Id30
impl AsExpression<Nullable<Integer>> for Id30
§type Expression = Bound<Nullable<Integer>, Id30>
type Expression = Bound<Nullable<Integer>, Id30>
source§fn as_expression(self) -> Self::Expression
fn as_expression(self) -> Self::Expression
source§impl<'de> Deserialize<'de> for Id30
impl<'de> Deserialize<'de> for Id30
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
source§impl Distribution<Id30> for Standard
impl Distribution<Id30> for Standard
source§impl Ord for Id30
impl Ord for Id30
source§impl PartialEq for Id30
impl PartialEq for Id30
source§impl PartialOrd for Id30
impl PartialOrd for Id30
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 moreimpl Copy for Id30
impl Eq for Id30
impl StructuralPartialEq for Id30
Auto Trait Implementations§
impl Freeze for Id30
impl RefUnwindSafe for Id30
impl Send for Id30
impl Sync for Id30
impl Unpin for Id30
impl UnwindSafe for Id30
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoSql for T
impl<T> IntoSql for T
source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
self
to an expression for Diesel’s query builder. Read moresource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
&self
to an expression for Diesel’s query builder. Read more