Skip to content

Commit

Permalink
impl From<Url> for StreamerUri
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-numeus committed Jul 6, 2024
1 parent a3efff8 commit be34c74
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions sea-streamer-types/src/streamer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ impl Display for StreamerUri {
}
}

impl From<Url> for StreamerUri {
fn from(value: Url) -> Self {
Self { nodes: vec![value] }
}
}

impl FromIterator<Url> for StreamerUri {
fn from_iter<T: IntoIterator<Item = Url>>(iter: T) -> Self {
Self {
nodes: iter.into_iter().collect(),
}
}
}

impl StreamerUri {
pub fn zero() -> Self {
Self { nodes: Vec::new() }
Expand Down Expand Up @@ -347,6 +361,23 @@ mod test {
assert_eq!(uri.nodes(), &["file:///path/to/hi".parse().unwrap()]);
}

#[test]
fn test_into_streamer_uri() {
let url: Url = "proto://sea-ql.org:1234".parse().unwrap();
let uri: StreamerUri = url.clone().into();
assert!(uri.nodes.len() == 1);
assert_eq!(url, uri.nodes.first().unwrap().clone());

let urls: [Url; 3] = [
"proto://sea-ql.org:1".parse().unwrap(),
"proto://sea-ql.org:2".parse().unwrap(),
"proto://sea-ql.org:3".parse().unwrap(),
];
let uri: StreamerUri = StreamerUri::from_iter(urls.clone().into_iter());
assert!(uri.nodes.len() == 3);
assert!(uri.nodes.iter().eq(urls.iter()));
}

#[test]
fn test_parse_stream_url_err() {
use crate::StreamKeyErr;
Expand Down

0 comments on commit be34c74

Please sign in to comment.