Skip to content

Commit

Permalink
refactor: use Into bound for KeyExpr::with_parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
wyfo committed Apr 25, 2024
1 parent d9b65a7 commit 8c8d637
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
15 changes: 5 additions & 10 deletions zenoh/src/key_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ use zenoh_protocol::{
};
use zenoh_result::ZResult;

use crate::{net::primitives::Primitives, prelude::Selector, Session, Undeclarable};
use crate::{
net::primitives::Primitives, prelude::Selector, selector::Parameters, Session, Undeclarable,
};

#[derive(Clone, Debug)]
pub(crate) enum KeyExprInner<'a> {
Expand Down Expand Up @@ -302,17 +304,10 @@ impl<'a> KeyExpr<'a> {
}
}

pub fn with_parameters(self, selector: &'a str) -> Selector<'a> {
Selector {
key_expr: self,
parameters: selector.into(),
}
}

pub fn with_owned_parameters(self, selector: String) -> Selector<'a> {
pub fn with_parameters<P: Into<Parameters<'a>>>(self, parameters: P) -> Selector<'a> {
Selector {
key_expr: self,
parameters: selector.into(),
parameters: parameters.into(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion zenoh/src/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl TryFrom<String> for Selector<'_> {
Some(qmark_position) => {
let parameters = s[qmark_position + 1..].to_owned();
s.truncate(qmark_position);
Ok(KeyExpr::try_from(s)?.with_owned_parameters(parameters))
Ok(KeyExpr::try_from(s)?.with_parameters(parameters))
}
None => Ok(KeyExpr::try_from(s)?.into()),
}
Expand Down

0 comments on commit 8c8d637

Please sign in to comment.