Compare commits

...

7 Commits

Author SHA1 Message Date
nitn3lav fa584489aa
Merge 1931388bf2 into 3f9d88f859 2025-07-03 12:52:12 -04:00
dependabot[bot] 3f9d88f859
build(deps): bump taiki-e/install-action from 2.54.0 to 2.54.3 (#3686)
Bumps [taiki-e/install-action](https://github.com/taiki-e/install-action) from 2.54.0 to 2.54.3.
- [Release notes](https://github.com/taiki-e/install-action/releases)
- [Changelog](https://github.com/taiki-e/install-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/taiki-e/install-action/compare/v2.54.0...v2.54.3)

---
updated-dependencies:
- dependency-name: taiki-e/install-action
  dependency-version: 2.54.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-06-30 22:59:38 +00:00
dependabot[bot] 2eb801cb59
build(deps): bump taiki-e/cache-cargo-install-action from 2.1.2 to 2.2.0 (#3687)
Bumps [taiki-e/cache-cargo-install-action](https://github.com/taiki-e/cache-cargo-install-action) from 2.1.2 to 2.2.0.
- [Release notes](https://github.com/taiki-e/cache-cargo-install-action/releases)
- [Changelog](https://github.com/taiki-e/cache-cargo-install-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/taiki-e/cache-cargo-install-action/compare/v2.1.2...v2.2.0)

---
updated-dependencies:
- dependency-name: taiki-e/cache-cargo-install-action
  dependency-version: 2.2.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-06-30 22:58:36 +00:00
Rob Ede 1931388bf2
Merge branch 'master' into master 2022-09-25 15:41:40 +01:00
Valentin Leistner 8d6c23038a add tests for `deserialize_any` 2022-09-25 12:02:19 +02:00
Valentin Leistner 6df38522eb fix `deserialize_any` for `seq` and `map` 2022-09-25 12:02:19 +02:00
Valentin Leistner ae2ee7fff1 PathDeserializer: use `deserialize_str` for `deserialize_any` 2022-09-25 12:02:19 +02:00
5 changed files with 117 additions and 10 deletions

View File

@ -49,7 +49,7 @@ jobs:
toolchain: ${{ matrix.version.version }}
- name: Install just, cargo-hack, cargo-nextest, cargo-ci-cache-clean
uses: taiki-e/install-action@v2.54.0
uses: taiki-e/install-action@v2.54.3
with:
tool: just,cargo-hack,cargo-nextest,cargo-ci-cache-clean
@ -83,7 +83,7 @@ jobs:
uses: actions-rust-lang/setup-rust-toolchain@v1.13.0
- name: Install just, cargo-hack
uses: taiki-e/install-action@v2.54.0
uses: taiki-e/install-action@v2.54.3
with:
tool: just,cargo-hack

View File

@ -64,7 +64,7 @@ jobs:
toolchain: ${{ matrix.version.version }}
- name: Install just, cargo-hack, cargo-nextest, cargo-ci-cache-clean
uses: taiki-e/install-action@v2.54.0
uses: taiki-e/install-action@v2.54.3
with:
tool: just,cargo-hack,cargo-nextest,cargo-ci-cache-clean
@ -113,7 +113,7 @@ jobs:
toolchain: nightly
- name: Install just
uses: taiki-e/install-action@v2.54.0
uses: taiki-e/install-action@v2.54.3
with:
tool: just

View File

@ -24,7 +24,7 @@ jobs:
components: llvm-tools
- name: Install just, cargo-llvm-cov, cargo-nextest
uses: taiki-e/install-action@v2.54.0
uses: taiki-e/install-action@v2.54.3
with:
tool: just,cargo-llvm-cov,cargo-nextest

View File

@ -77,12 +77,12 @@ jobs:
toolchain: ${{ vars.RUST_VERSION_EXTERNAL_TYPES }}
- name: Install just
uses: taiki-e/install-action@v2.54.0
uses: taiki-e/install-action@v2.54.3
with:
tool: just
- name: Install cargo-check-external-types
uses: taiki-e/cache-cargo-install-action@v2.1.2
uses: taiki-e/cache-cargo-install-action@v2.2.0
with:
tool: cargo-check-external-types

View File

@ -27,6 +27,9 @@ macro_rules! unsupported_type {
macro_rules! parse_single_value {
($trait_fn:ident) => {
parse_single_value!($trait_fn, $trait_fn);
};
($trait_fn:ident, $visit_fn:ident) => {
fn $trait_fn<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>,
@ -43,7 +46,7 @@ macro_rules! parse_single_value {
Value {
value: &self.path[0],
}
.$trait_fn(visitor)
.$visit_fn(visitor)
}
}
};
@ -205,11 +208,11 @@ impl<'de, T: ResourcePath + 'de> Deserializer<'de> for PathDeserializer<'de, T>
})
}
unsupported_type!(deserialize_any, "'any'");
unsupported_type!(deserialize_option, "Option<T>");
unsupported_type!(deserialize_identifier, "identifier");
unsupported_type!(deserialize_ignored_any, "ignored_any");
parse_single_value!(deserialize_any, deserialize_str);
parse_single_value!(deserialize_bool);
parse_single_value!(deserialize_i8);
parse_single_value!(deserialize_i16);
@ -427,7 +430,13 @@ impl<'de> Deserializer<'de> for Value<'de> {
Err(de::value::Error::custom("unsupported type: tuple struct"))
}
unsupported_type!(deserialize_any, "any");
fn deserialize_any<V>(self, v: V) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>,
{
self.deserialize_str(v)
}
unsupported_type!(deserialize_seq, "seq");
unsupported_type!(deserialize_map, "map");
unsupported_type!(deserialize_identifier, "identifier");
@ -704,6 +713,104 @@ mod tests {
assert_eq!(vals.value, "/");
}
#[test]
fn deserialize_path_decode_any() {
#[derive(Debug, PartialEq)]
pub enum AnyEnumCustom {
String(String),
Int(u32),
Other,
}
impl<'de> Deserialize<'de> for AnyEnumCustom {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
struct Vis;
impl<'de> Visitor<'de> for Vis {
type Value = AnyEnumCustom;
fn expecting<'a>(
&self,
f: &mut std::fmt::Formatter<'a>,
) -> std::fmt::Result {
write!(f, "my thing")
}
fn visit_u32<E>(self, v: u32) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
Ok(AnyEnumCustom::Int(v))
}
fn visit_str<E: serde::de::Error>(self, v: &str) -> Result<Self::Value, E> {
v.parse().map(AnyEnumCustom::Int).or_else(|_| {
Ok(match v {
"other" => AnyEnumCustom::Other,
_ => AnyEnumCustom::String(format!("some str: {v}")),
})
})
}
}
deserializer.deserialize_any(Vis)
}
}
#[derive(Debug, Deserialize, PartialEq)]
#[serde(untagged)]
pub enum AnyEnumDerive {
String(String),
Int(u32),
Other,
}
// single
let rdef = ResourceDef::new("/{key}");
let mut path = Path::new("/%25");
rdef.capture_match_info(&mut path);
let de = PathDeserializer::new(&path);
let segment: AnyEnumCustom = serde::Deserialize::deserialize(de).unwrap();
assert_eq!(segment, AnyEnumCustom::String("some str: %".to_string()));
let mut path = Path::new("/%25");
rdef.capture_match_info(&mut path);
let de = PathDeserializer::new(&path);
let segment: AnyEnumDerive = serde::Deserialize::deserialize(de).unwrap();
assert_eq!(segment, AnyEnumDerive::String("%".to_string()));
// seq
let rdef = ResourceDef::new("/{key}/{value}");
let mut path = Path::new("/other/123");
rdef.capture_match_info(&mut path);
let de = PathDeserializer::new(&path);
let segment: (AnyEnumCustom, AnyEnumDerive) =
serde::Deserialize::deserialize(de).unwrap();
assert_eq!(segment.0, AnyEnumCustom::Other);
// Deserializes to `String` instead of `Int` because deserializing defaults to `str` and serde doesn't automatically implement parsing numbers from `&str`s
assert_eq!(segment.1, AnyEnumDerive::String("123".to_string()));
// map
#[derive(Deserialize)]
struct Vals {
key: AnyEnumCustom,
value: AnyEnumDerive,
}
let rdef = ResourceDef::new("/{key}/{value}");
let mut path = Path::new("/123/%2F");
rdef.capture_match_info(&mut path);
let de = PathDeserializer::new(&path);
let vals: Vals = serde::Deserialize::deserialize(de).unwrap();
assert_eq!(vals.key, AnyEnumCustom::Int(123));
assert_eq!(vals.value, AnyEnumDerive::String("/".to_string()));
}
#[test]
fn deserialize_borrowed() {
#[derive(Debug, Deserialize)]