Skip to main content

Source

Struct Source 

Source
pub struct Source { /* private fields */ }
Expand description

An NDI source: its name and, when known, its network address.

Equality and hashing compare the complete name and address text; they do not imply persistent device identity.

The name typically includes the machine name and source name (e.g., “MACHINE (Source)”). A source found by a Finder has the address it advertises; a receiver given a source without one looks it up by name.

§Examples

use grafton_ndi::{Source, SourceAddress};

let source = Source::new("LAPTOP (Camera 1)").unwrap()
    .with_address(SourceAddress::new("192.168.1.100:5960".to_string()).unwrap());
assert_eq!(source.name(), "LAPTOP (Camera 1)");
assert_eq!(source.to_string(), "LAPTOP (Camera 1)@192.168.1.100:5960");
assert!(Source::new("LAPTOP (Camera 1)").unwrap().address().is_none());

Implementations§

Source§

impl Source

Source

pub fn new(name: impl Into<String>) -> Result<Self>

The source named name, without an address.

§Errors

Returns Error::InvalidCString when the name contains a NUL byte.

Source

pub fn with_address(self, address: SourceAddress) -> Self

This source, at address.

Source

pub fn name(&self) -> &str

The NDI source name (e.g., “MACHINE (Source Name)”). A source the SDK described by its address alone has an empty name.

Source

pub fn address(&self) -> Option<&SourceAddress>

The network address for connecting to this source, when known.

Source

pub fn matches_host(&self, host: &str) -> bool

Check if this source matches a hostname, IP address or NDI machine name.

An IP query checks the complete address host numerically; IP literals may have enclosing square brackets. A DNS hostname checks both the address host and the machine component of an SDK MACHINE (Source Name) label. Other machine-name queries check only that machine component, never the label’s source name or an address.

Names are nonempty and at most 253 bytes after an optional final dot is removed. They have no control characters, leading or trailing whitespace, endpoint/URI delimiters (: / ? # @ [ ]), or label delimiters (( )). Dotted-numeric text must be a complete IP address. DNS hostnames use ASCII letters, digits and interior hyphens in labels of at most 63 bytes; other accepted names, including spaces and underscores, are machine names. Both name cases ignore a final dot and fold only ASCII letters: other Unicode characters compare exactly. Invalid queries return false.

§Arguments
  • host - The hostname, IP address or machine name to match against
§Examples
use grafton_ndi::{Source, SourceAddress};

let source = Source::new("CAMERA1 (Chan1, 192.168.0.107)").unwrap()
    .with_address(SourceAddress::new("192.168.0.107:5960".to_string()).unwrap());

assert!(source.matches_host("192.168.0.107"));
assert!(source.matches_host("CAMERA1"));
assert!(!source.matches_host("192.168.1.1"));
Source

pub fn host(&self) -> Option<&str>

Extract the host from conventional host/port or URL syntax.

Reads the authority before any path, query or fragment and removes brackets around IPv6 literals. A URL with an empty port field still has a host. SDK addresses are opaque and unrecognized syntax returns None.

For IP-based sources, this returns the IP portion without the port. For URL-based sources, this extracts the hostname portion, which may be a name such as camera.local rather than an IP address.

§Returns

Some(host) if an IP or hostname is found, None otherwise.

§Examples
use grafton_ndi::{Source, SourceAddress};

let source = Source::new("CAMERA1").unwrap()
    .with_address(SourceAddress::new("192.168.1.100:5960".to_string()).unwrap());

assert_eq!(source.host(), Some("192.168.1.100"));

Trait Implementations§

Source§

impl Clone for Source

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 Source

Source§

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

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

impl Display for Source

Source§

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

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

impl Eq for Source

Source§

impl Hash for Source

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Source

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 StructuralPartialEq for Source

Source§

impl TryFrom<&Source> for SourceSpec

Source§

type Error = Error

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

fn try_from(source: &Source) -> Result<Self>

Performs the conversion.

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.