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
impl Source
Sourcepub fn new(name: impl Into<String>) -> Result<Self>
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.
Sourcepub fn with_address(self, address: SourceAddress) -> Self
pub fn with_address(self, address: SourceAddress) -> Self
This source, at address.
Sourcepub fn name(&self) -> &str
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.
Sourcepub fn address(&self) -> Option<&SourceAddress>
pub fn address(&self) -> Option<&SourceAddress>
The network address for connecting to this source, when known.
Sourcepub fn matches_host(&self, host: &str) -> bool
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"));Sourcepub fn host(&self) -> Option<&str>
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"));