pub struct Source {
pub name: String,
pub address: SourceAddress,
}Expand description
Represents an NDI source discovered on the network.
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 method checks both the source name and address for a match, making it easy to find sources by hostname or IP.
§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 IP address from this source if available.
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"));