Struct Callsign
pub struct Callsign(/* private fields */);Expand description
D-STAR callsign (8 bytes, ASCII, space-padded on the right).
§Invariants
- Constructed via
Self::try_from_str: ASCII, 1..=8 bytes after trimming trailing whitespace, space-padded to exactly 8 bytes. - Constructed via
Self::from_wire_bytes: any 8 bytes, verbatim. Used on the receive path where real reflectors emit non-printable bytes.
Implementations§
§impl Callsign
impl Callsign
pub fn try_from_str(s: &str) -> Result<Callsign, TypeError>
pub fn try_from_str(s: &str) -> Result<Callsign, TypeError>
Try to build a Callsign from a string slice.
- Must be ASCII
- Must be 1..=8 bytes (trailing whitespace is trimmed before length check, then space-padded to exactly 8 bytes)
§Errors
Returns TypeError::InvalidCallsign if s is empty, longer
than 8 bytes after trimming, or contains non-ASCII characters.
§Example
use dstar_gateway_core::Callsign;
let cs = Callsign::try_from_str("W1AW")?;
assert_eq!(cs.as_bytes(), b"W1AW "); // space-padded to 8 bytespub const fn from_wire_bytes(bytes: [u8; 8]) -> Callsign
pub const fn from_wire_bytes(bytes: [u8; 8]) -> Callsign
Build a Callsign directly from 8 wire bytes, storing them
verbatim without any validation.
Used on the receive path. Mirrors ircDDBGateway’s
memcpy(m_myCall1, data + 44U, LONG_CALLSIGN_LENGTH) from
Common/HeaderData.cpp:622. Real reflectors emit non-printable
bytes in callsign fields and a strict ASCII filter would
silently drop those headers.
pub fn as_str(&self) -> Cow<'_, str>
pub fn as_str(&self) -> Cow<'_, str>
Return the trimmed string (no trailing spaces).
Uses lossy UTF-8 conversion via String::from_utf8_lossy so
wire bytes stored verbatim via Self::from_wire_bytes that
are not valid UTF-8 are rendered with U+FFFD replacement
characters rather than panicking.