pub struct XHandle(/* private fields */);Expand description
An X handle (aka username).
Contains 1–20 ASCII letters, digits, or underscores. MAX_LENGTH is the
compatibility ceiling: current X usernames are limited to 15 characters,
but legacy accounts include handles longer than that, such as
@richardrushfield (16 characters). Parsing drops one optional @.
Spelling is preserved, while equality, ordering, and hashing ignore ASCII
case.
§Legacy compatibility
X’s current help page specifies 15 characters. Twitter’s archived 2010
and 2016 help pages also describe that limit, but the 2010 page explicitly
preserves longer “early bird” usernames without publishing their hard upper
bound. This type uses the historically reported 20-character compatibility
ceiling and covers the known 16-character richardrushfield account.
Longer inputs are rejected, never truncated.
use known_types_x::XHandle;
let legacy: XHandle = "@richardrushfield".parse()?;
assert_eq!(legacy.as_str(), "richardrushfield");
assert!(legacy.as_str().len() > XHandle::CURRENT_MAX_LENGTH);See the shared handle contract and
crate-level integration recipes. With async-graphql, the scalar
is named XHandle.
Implementations§
Source§impl XHandle
impl XHandle
Sourcepub const MIN_LENGTH: usize = 1
pub const MIN_LENGTH: usize = 1
Minimum length of the normalized handle, in Unicode scalar values.
Sourcepub const MAX_LENGTH: usize = 20
pub const MAX_LENGTH: usize = 20
Maximum representational length, in Unicode scalar values.
This is the widest known current or historical upstream bound, not necessarily the current registration limit.
Sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Consume the handle and return its stored spelling.
Source§impl XHandle
impl XHandle
Sourcepub const CURRENT_MAX_LENGTH: usize = 15
pub const CURRENT_MAX_LENGTH: usize = 15
Current X username maximum for new registrations and edits.
Sourcepub const HISTORICAL_MAX_LENGTH: usize = 20
pub const HISTORICAL_MAX_LENGTH: usize = 20
Historical compatibility maximum used by legacy Twitter accounts.