Skip to main content

NdefRecord

Struct NdefRecord 

Source
pub struct NdefRecord {
    pub record_type: String,
    pub media_type: Option<String>,
    pub id: Option<String>,
    pub encoding: Option<String>,
    pub lang: Option<String>,
    pub data: Option<String>,
    pub data_base64: Option<Bytes>,
}
Expand description

One NDEF record, as Web NFC’s NDEFRecordInit.

use hardless_core::NdefRecord;
let text: NdefRecord =
    serde_json::from_str(r#"{ "recordType": "text", "data": "Hello", "lang": "en" }"#).unwrap();
assert_eq!(text.payload(), b"Hello");
let png: NdefRecord = serde_json::from_str(
    r#"{ "recordType": "mime", "mediaType": "image/png", "dataBase64": "iVBORw==" }"#,
).unwrap();
assert_eq!(png.payload(), b"\x89PNG");
assert!(text.validate().is_ok() && png.validate().is_ok());

Fields§

§record_type: String

empty, text, url, absolute-url, mime, unknown, or an external type such as example.com:loyalty.

§media_type: Option<String>

The MIME type of a mime record, e.g. application/json.

§id: Option<String>

The record identifier.

§encoding: Option<String>

The text encoding of a text record: utf-8 (default), utf-16, utf-16be or utf-16le.

§lang: Option<String>

The language of a text record, e.g. en.

§data: Option<String>

A text payload: the text of a text record, the URL of a url record, or any payload that is UTF-8 text.

§data_base64: Option<Bytes>

A binary payload, base64. At most one of data and dataBase64 is set.

Implementations§

Source§

impl NdefRecord

Source

pub fn text(text: impl Into<String>) -> Self

A text record.

assert_eq!(hardless_core::NdefRecord::text("Hi").record_type, "text");
Source

pub fn url(url: impl Into<String>) -> Self

A url record.

Source

pub fn payload(&self) -> Vec<u8> ⓘ

The payload bytes: data as UTF-8, or the decoded dataBase64.

Source

pub fn validate(&self) -> Result<(), String>

Checks the record the way Web NFC checks an NDEFRecordInit before writing it.

Trait Implementations§

Source§

impl Clone for NdefRecord

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NdefRecord

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for NdefRecord

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for NdefRecord

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for NdefRecord

Source§

impl JsonSchema for NdefRecord

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl PartialEq for NdefRecord

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for NdefRecord

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for NdefRecord

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.