pub struct Source {
pub name: String,
pub address: SourceAddress,
}Expand description
Represents an NDI source discovered on the network.
Equality and hashing compare the complete name and address, including the address variant; they do not imply persistent device identity.
Sources contain a human-readable name and network address. The name typically includes the machine name and source name (e.g., “MACHINE (Source)”).
§Examples
use grafton_ndi::{Source, SourceAddress};
let source = Source {
name: "LAPTOP (Camera 1)".to_string(),
address: SourceAddress::Ip("192.168.1.100:5960".to_string()),
};
println!("Source: {}", source); // Displays: LAPTOP (Camera 1)@192.168.1.100:5960Fields§
§name: StringThe NDI source name (e.g., “MACHINE (Source Name)”).
address: SourceAddressThe network address for connecting to this source.
Implementations§
Source§impl Source
impl Source
Sourcepub fn matches_host(&self, host: &str) -> bool
pub fn matches_host(&self, host: &str) -> bool
Check if this source matches a given host or IP address.
This checks the complete address host, or for hostname queries the
machine component of an SDK MACHINE (Source Name) label.
§Arguments
host- The hostname or IP address to match against
§Examples
use grafton_ndi::{Source, SourceAddress};
let source = Source {
name: "CAMERA1 (Chan1, 192.168.0.107)".to_string(),
address: SourceAddress::Ip("192.168.0.107:5960".to_string()),
};
assert!(source.matches_host("192.168.0.107"));
assert!(source.matches_host("CAMERA1"));
assert!(!source.matches_host("192.168.1.1"));Sourcepub fn ip_address(&self) -> Option<&str>
pub fn ip_address(&self) -> Option<&str>
Extract the host from conventional host/port or URL syntax.
Brackets around IPv6 literals are removed. SDK addresses are opaque;
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.
§Returns
Some(ip) if an IP or hostname is found, None otherwise.
§Examples
use grafton_ndi::{Source, SourceAddress};
let source = Source {
name: "CAMERA1".to_string(),
address: SourceAddress::Ip("192.168.1.100:5960".to_string()),
};
assert_eq!(source.ip_address(), Some("192.168.1.100"));Sourcepub fn host(&self) -> Option<&str>
pub fn host(&self) -> Option<&str>
Extract the hostname or IP without port.
This is an alias for ip_address() for better API discoverability.
§Examples
use grafton_ndi::{Source, SourceAddress};
let source = Source {
name: "CAMERA1".to_string(),
address: SourceAddress::Ip("192.168.1.100:5960".to_string()),
};
assert_eq!(source.host(), Some("192.168.1.100"));