Do not require major bump

This commit is contained in:
Yuki Okushi 2026-02-01 10:47:31 +09:00
parent ac0ca678e5
commit 9ff042778c
2 changed files with 14 additions and 23 deletions

View File

@ -243,7 +243,7 @@ impl HttpRequest {
U: IntoIterator<Item = I>, U: IntoIterator<Item = I>,
I: AsRef<str>, I: AsRef<str>,
{ {
self.resource_map().url_for_iter(self, name, elements) self.resource_map().url_for(self, name, elements)
} }
/// Generates URL for a named resource. /// Generates URL for a named resource.

View File

@ -119,7 +119,7 @@ impl ResourceMap {
/// Generate URL for named resource with an iterator over elements. /// Generate URL for named resource with an iterator over elements.
/// ///
/// Check [`HttpRequest::url_for`] for detailed information. /// Check [`HttpRequest::url_for`] for detailed information.
pub fn url_for_iter<U, I>( pub fn url_for<U, I>(
&self, &self,
req: &HttpRequest, req: &HttpRequest,
name: &str, name: &str,
@ -130,7 +130,7 @@ impl ResourceMap {
I: AsRef<str>, I: AsRef<str>,
{ {
let mut elements = elements.into_iter(); let mut elements = elements.into_iter();
self.url_for(req, name, |mut acc, node: &ResourceMap| { self.url_for_with(req, name, |mut acc, node: &ResourceMap| {
node.pattern node.pattern
.resource_path_from_iter(&mut acc, &mut elements) .resource_path_from_iter(&mut acc, &mut elements)
.then_some(acc) .then_some(acc)
@ -151,14 +151,14 @@ impl ResourceMap {
V: AsRef<str>, V: AsRef<str>,
S: BuildHasher, S: BuildHasher,
{ {
self.url_for(req, name, |mut acc, node: &ResourceMap| { self.url_for_with(req, name, |mut acc, node: &ResourceMap| {
node.pattern node.pattern
.resource_path_from_map(&mut acc, elements) .resource_path_from_map(&mut acc, elements)
.then_some(acc) .then_some(acc)
}) })
} }
fn url_for<F>( fn url_for_with<F>(
&self, &self,
req: &HttpRequest, req: &HttpRequest,
name: &str, name: &str,
@ -485,7 +485,7 @@ mod tests {
const OUTPUT: &str = "http://localhost:8888/user/u123/post/foobar"; const OUTPUT: &str = "http://localhost:8888/user/u123/post/foobar";
let url = rmap let url = rmap
.url_for_iter(&req, "post", ["u123", "foobar"]) .url_for(&req, "post", ["u123", "foobar"])
.unwrap() .unwrap()
.to_string(); .to_string();
assert_eq!(url, OUTPUT); assert_eq!(url, OUTPUT);
@ -497,7 +497,7 @@ mod tests {
.to_string(); .to_string();
assert_eq!(url, OUTPUT); assert_eq!(url, OUTPUT);
assert!(rmap.url_for_iter(&req, "missing", ["u123"]).is_err()); assert!(rmap.url_for(&req, "missing", ["u123"]).is_err());
assert!(rmap.url_for_map(&req, "missing", &input_map).is_err()); assert!(rmap.url_for_map(&req, "missing", &input_map).is_err());
} }
@ -530,25 +530,21 @@ mod tests {
const OUTPUT: &str = "/quick%20brown%20fox/%nan%3Fquery%23frag"; const OUTPUT: &str = "/quick%20brown%20fox/%nan%3Fquery%23frag";
let url = rmap.url_for_iter(&req, "internal", ITERABLE_INPUT).unwrap(); let url = rmap.url_for(&req, "internal", ITERABLE_INPUT).unwrap();
assert_eq!(url.path(), OUTPUT); assert_eq!(url.path(), OUTPUT);
let url = rmap.url_for_map(&req, "internal", &map_input).unwrap(); let url = rmap.url_for_map(&req, "internal", &map_input).unwrap();
assert_eq!(url.path(), OUTPUT); assert_eq!(url.path(), OUTPUT);
let url = rmap let url = rmap.url_for(&req, "external.1", ITERABLE_INPUT).unwrap();
.url_for_iter(&req, "external.1", ITERABLE_INPUT)
.unwrap();
assert_eq!(url.path(), OUTPUT); assert_eq!(url.path(), OUTPUT);
let url = rmap.url_for_map(&req, "external.1", &map_input).unwrap(); let url = rmap.url_for_map(&req, "external.1", &map_input).unwrap();
assert_eq!(url.path(), OUTPUT); assert_eq!(url.path(), OUTPUT);
assert!(rmap assert!(rmap.url_for(&req, "external.2", ITERABLE_INPUT).is_err());
.url_for_iter(&req, "external.2", ITERABLE_INPUT)
.is_err());
assert!(rmap.url_for_map(&req, "external.2", &map_input).is_err()); assert!(rmap.url_for_map(&req, "external.2", &map_input).is_err());
let empty_map: HashMap<&str, &str> = HashMap::new(); let empty_map: HashMap<&str, &str> = HashMap::new();
assert!(rmap.url_for_iter(&req, "external.2", [""]).is_err()); assert!(rmap.url_for(&req, "external.2", [""]).is_err());
assert!(rmap.url_for_map(&req, "external.2", &empty_map).is_err()); assert!(rmap.url_for_map(&req, "external.2", &empty_map).is_err());
} }
@ -585,9 +581,7 @@ mod tests {
const OUTPUT: &str = "https://duck.com/abcd"; const OUTPUT: &str = "https://duck.com/abcd";
assert_eq!( assert_eq!(
rmap.url_for_iter(&req, "duck", ["abcd"]) rmap.url_for(&req, "duck", ["abcd"]).unwrap().to_string(),
.unwrap()
.to_string(),
OUTPUT OUTPUT
); );
@ -625,10 +619,7 @@ mod tests {
const OUTPUT: &str = "http://localhost:8080/bar/nested"; const OUTPUT: &str = "http://localhost:8080/bar/nested";
let url = rmap let url = rmap.url_for(&req, "nested", [""; 0]).unwrap().to_string();
.url_for_iter(&req, "nested", [""; 0])
.unwrap()
.to_string();
assert_eq!(url, OUTPUT); assert_eq!(url, OUTPUT);
let empty_map: HashMap<&str, &str> = HashMap::new(); let empty_map: HashMap<&str, &str> = HashMap::new();
@ -638,7 +629,7 @@ mod tests {
.to_string(); .to_string();
assert_eq!(url, OUTPUT); assert_eq!(url, OUTPUT);
assert!(rmap.url_for_iter(&req, "missing", ["u123"]).is_err()); assert!(rmap.url_for(&req, "missing", ["u123"]).is_err());
assert!(rmap.url_for_map(&req, "missing", &empty_map).is_err()); assert!(rmap.url_for_map(&req, "missing", &empty_map).is_err());
} }
} }