pub struct Collation { /* private fields */ }Expand description
A collation that this crate can compare with, or an explicit refusal.
Construct one of these, then call Collation::compare. Construction fails
closed: anything not modelled exactly yields Error.
Serialization round-trips the description (Backend); deserialization
re-runs the same validated construction, so a tampered or stale payload
cannot produce an unchecked Collation.
Implementations§
Source§impl Collation
impl Collation
Sourcepub const fn postgres_c() -> Self
pub const fn postgres_c() -> Self
PostgreSQL C/POSIX, bytewise.
Sourcepub fn postgres_icu(
locale: impl Into<String>,
deterministic: bool,
source_version: VersionId,
) -> Result<Self>
pub fn postgres_icu( locale: impl Into<String>, deterministic: bool, source_version: VersionId, ) -> Result<Self>
Construct a PostgreSQL ICU collation, validating the version at runtime.
Returns Error::VersionMismatch if source_version does not match the
ICU data the linked backend would use, and Error::Unsupported for
custom rules or non-ICU providers.
Sourcepub fn postgres(spec: PostgresCollation) -> Result<Self>
pub fn postgres(spec: PostgresCollation) -> Result<Self>
Construct a collation from a fully resolved PostgreSQL description.
Refuses configurations this crate cannot reproduce exactly: libc
providers other than C/POSIX, custom ICU rules, and non-UTF-8
sources.
Sourcepub fn mysql_0900_ai_ci() -> Self
Available on crate feature mysql-uca only.
pub fn mysql_0900_ai_ci() -> Self
mysql-uca only.Construct the modelled MySQL utf8mb4_0900_ai_ci collation.
Only available with the mysql-uca feature (enabled by default). Use
Collation::mysql when the feature set is not known at compile time;
it returns Error::FeatureDisabled instead.
Sourcepub fn mysql_unicode_ci() -> Self
Available on crate feature mysql-uca only.
pub fn mysql_unicode_ci() -> Self
mysql-uca only.Construct the modelled MySQL utf8mb4_unicode_ci collation.
Only available with the mysql-uca feature (enabled by default). Use
Collation::mysql when the feature set is not known at compile time;
it returns Error::FeatureDisabled instead.
Sourcepub fn mysql(spec: MysqlCollation) -> Result<Self>
pub fn mysql(spec: MysqlCollation) -> Result<Self>
Construct a collation from a fully resolved MySQL description.
Sourcepub fn oracle(spec: OracleCollation) -> Result<Self>
pub fn oracle(spec: OracleCollation) -> Result<Self>
Construct a collation from a fully resolved Oracle description.
Only NLS_SORT=BINARY on AL32UTF8 VARCHAR2 (bytewise) and the
UCA0700_DUCET / UCA1210_DUCET collations are reproducible. Every
other Oracle collation — monolingual, _M, BINARY_CI/BINARY_AI,
*_ROOT, *_ORADUCET, tailored UCA, non-AL32UTF8, blank-padded — is
refused with Error::Unsupported.
Sourcepub fn from_mysql_name_unspecified_version(name: &str) -> Result<Self>
pub fn from_mysql_name_unspecified_version(name: &str) -> Result<Self>
Resolve a MySQL collation by name without a version, refusing any
name whose semantics depend on the server version.
This is intentionally conservative. Prefer Collation::mysql with an
explicit MysqlCollation resolved by the caller.
Sourcepub fn compare(&self, a: &str, b: &str) -> Result<Ordering>
pub fn compare(&self, a: &str, b: &str) -> Result<Ordering>
Compare two UTF-8 strings exactly as the source database would.
This is the primary operation. Sort keys are intentionally not part of
the stable API: the contract is a three-way comparison, and a collation
that also defines a bytewise tie-break (PostgreSQL deterministic
collations) cannot be reproduced by a single ICU sort key, which encodes
only the primary ICU comparison.
Returns Error if the underlying backend fails at runtime. The binary
backend never fails; the ICU backend can, and a failed comparison is
never silently reported as equality.
Sourcepub fn equal(&self, a: &str, b: &str) -> Result<bool>
pub fn equal(&self, a: &str, b: &str) -> Result<bool>
Whether a and b are equal under this collation.
Returns Error for the same reasons as Collation::compare.
Sourcepub fn from_backend(backend: Backend) -> Result<Self>
pub fn from_backend(backend: Backend) -> Result<Self>
Build a collation from a resolved Backend description, re-running the
same validation as the public constructors.
This is the single construction path used by deserialization, so an arbitrary or stale description cannot bypass the support boundary.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Collation
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Collation
serde only.