Skip to main content

Nfc

Struct Nfc 

Source
pub struct Nfc<R: Runtime>(/* private fields */);
Expand description

Access to the nfc APIs.

Implementations§

Source§

impl<R: Runtime> Nfc<R>

Source

pub fn is_available(&self) -> Result<bool>

Checks whether NFC is supported by the device and currently usable by the app.

On Android this is false when the device has no NFC adapter or when NFC is disabled in the device settings. On iOS this is false when the NFCReaderUsageDescription entry is missing from the Info.plist file or when NFC tag reading is not available on the device.

Source

pub fn scan(&self, payload: ScanRequest) -> Result<ScanResponse>

Scans an NFC tag, blocking until a tag matching the given ScanRequest::kind filters is read or the scan fails.

Set ScanRequest::keep_session_alive to true to keep the connection to the tag open after it has been scanned, so that a following Self::write call writes to that tag.

§Errors

Returns an error when NFC is not available (see Self::is_available) or when the tag could not be read.

Source

pub fn write(&self, records: Vec<NfcRecord>) -> Result<()>

Writes the given NDEF records to an NFC tag, blocking until the write completes or fails.

Because this API does not take a scan kind, on Android it can only write to the tag of an ongoing session, so it must be preceded by a Self::scan call with ScanRequest::keep_session_alive set to true. On iOS an NDEF reader session is started when there is no ongoing session, and the records are written to the first tag that is scanned.

§Errors

Returns an error when NFC is not available (see Self::is_available), when there is no connected tag on Android, when the tag is read-only, when it cannot hold the message or when it does not support the NDEF format.

Auto Trait Implementations§

§

impl<R> !RefUnwindSafe for Nfc<R>

§

impl<R> !UnwindSafe for Nfc<R>

§

impl<R> Freeze for Nfc<R>
where PluginHandle<R>: Freeze,

§

impl<R> Send for Nfc<R>
where PluginHandle<R>: Send,

§

impl<R> Sync for Nfc<R>
where PluginHandle<R>: Sync,

§

impl<R> Unpin for Nfc<R>
where PluginHandle<R>: Unpin,

§

impl<R> UnsafeUnpin for Nfc<R>

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> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> MaybeSendSync for T

Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more