From 08f7adb9d7a965a703b22b3d54abe681606ba0fe Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Thu, 3 Mar 2022 09:47:20 -0800 Subject: [PATCH 1/5] add `From<&'a dyn Display>` for `Value` Signed-off-by: Eliza Weisman --- valuable/src/value.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/valuable/src/value.rs b/valuable/src/value.rs index d155287..4630a99 100644 --- a/valuable/src/value.rs +++ b/valuable/src/value.rs @@ -113,6 +113,12 @@ macro_rules! value { } } + impl<'a> From<&'a dyn fmt::Display> for Value<'a> { + fn from(src: &'a dyn fmt::Display) -> Self { + Self::Display(src) + } + } + impl fmt::Debug for Value<'_> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { use Value::*; From b6adbd6bdde74023c888ce80edc8dddeae1e9fd6 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Thu, 3 Mar 2022 09:54:52 -0800 Subject: [PATCH 2/5] handle other variants in `Value::as_display` Signed-off-by: Eliza Weisman --- valuable/src/value.rs | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/valuable/src/value.rs b/valuable/src/value.rs index 4630a99..6a781e0 100644 --- a/valuable/src/value.rs +++ b/valuable/src/value.rs @@ -721,6 +721,12 @@ macro_rules! convert { /// Return a `&dyn Display` representation of `self`, if possible. /// + /// If this value is a [`Value::Display`] variant, or any primitive + /// `Value` variant, this method will return a `&dyn Display` trait + /// object. Otherwise, if the value is [`Structable`], + /// [`Enumerable`], [`Tupleable`], [`Listable`], [`Mappable`], or a + /// [`Value::Path`], this method will return `None`. + /// /// # Examples /// /// ``` @@ -738,11 +744,40 @@ macro_rules! convert { /// let meters = Meters(5); /// /// assert!(Value::Display(&meters).as_display().is_some()); - /// assert!(Value::Bool(true).as_display().is_none()); + /// assert!(Value::Tupleable((true, "hello")).as_display().is_none()); /// ``` pub fn as_display(&self) -> Option<&dyn fmt::Display> { + use Value::*; match *self { - Value::Display(v) => Some(v), + I8(ref v) => Some(v), + I16(ref v) => Some(v), + I32(ref v) => Some(v), + I64(ref v) => Some(v), + I128(ref v) => Some(v), + Isize(ref v) => Some(v), + U8(ref v) => Some(v), + U16(ref v) => Some(v), + U32(ref v) => Some(v), + U64(ref v) => Some(v), + U128(ref v) => Some(v), + Usize(ref v) => Some(v), + F32(ref v) => Some(v), + F64(ref v) => Some(v), + Bool(ref v) => Some(v), + Char(ref v) => Some(v), + String(ref v) => Some(v), + + #[cfg(feature = "std")] + Error(ref v) => Some(v), + + // XXX(eliza): this, sadly, does not work for `Path`s; the + // only way to return them as a `Display` impl is + // `Path::display`, which creates a value owned by _this_ + // function; we can't return that as a trait object because + // we're borrowing it from the function's scope rather than + // from the value itself. + + Display(v) => Some(v), _ => None, } } From 3b983db3db9b6fd898a9fa63e29a181a4837dae3 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Thu, 3 Mar 2022 09:56:31 -0800 Subject: [PATCH 3/5] quote `Display` values in `Debug` impl This indicates that `Display` values are essentially being recorded as strings, rather than structured data, in the `Debug` output. Signed-off-by: Eliza Weisman --- valuable/src/value.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/valuable/src/value.rs b/valuable/src/value.rs index 6a781e0..d1dafaf 100644 --- a/valuable/src/value.rs +++ b/valuable/src/value.rs @@ -131,7 +131,7 @@ macro_rules! value { $(#[$attrs])* $variant(v) => fmt::Debug::fmt(v, fmt), )* - Display(d) => d.fmt(fmt), + Display(d) => write!(fmt, "\"{}\"", d), Unit => ().fmt(fmt), } } From 3b1abd64686728fb987dca3159c87165b8a9728b Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Thu, 3 Mar 2022 09:57:38 -0800 Subject: [PATCH 4/5] serde: serialize `Display` values Signed-off-by: Eliza Weisman --- valuable-serde/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/valuable-serde/src/lib.rs b/valuable-serde/src/lib.rs index 73d53d4..480be1f 100644 --- a/valuable-serde/src/lib.rs +++ b/valuable-serde/src/lib.rs @@ -265,6 +265,7 @@ where Value::Path(p) => Serialize::serialize(p, serializer), #[cfg(feature = "std")] Value::Error(e) => Err(S::Error::custom(e)), + Value::Display(d) => serializer.collect_str(d), v => unimplemented!("{:?}", v), } From 662a983562669f07c9c692c6eb0cf688d3c3886b Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Mon, 7 Mar 2022 12:24:25 +0900 Subject: [PATCH 5/5] Automatically creates PR when no_atomic.rs needs to be updated (#90) --- .github/workflows/ci.yml | 28 ++++++++++++++++++++++++---- valuable/no_atomic.rs | 1 - 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 66b5ca7..9264655 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,9 +72,6 @@ jobs: - run: cargo hack build --workspace --feature-powerset # When this job failed, run ci/no_atomic.sh and commit result changes. - # TODO(taiki-e): Ideally, this should be automated using a bot that creates - # PR when failed, but there is no bandwidth to implement it - # right now... codegen: runs-on: ubuntu-latest steps: @@ -82,7 +79,30 @@ jobs: - name: Install Rust run: rustup update nightly && rustup default nightly - run: ci/no_atomic.sh - - run: git diff --exit-code + - run: git add -N . && git diff --exit-code + if: github.repository_owner != 'tokio-rs' || github.event_name != 'schedule' + - id: diff + run: | + git config user.name "Taiki Endo" + git config user.email "te316e89@gmail.com" + git add -N . + if ! git diff --exit-code; then + git add . + git commit -m "Update no_atomic.rs" + echo "::set-output name=success::false" + fi + if: github.repository_owner == 'tokio-rs' && github.event_name == 'schedule' + - uses: peter-evans/create-pull-request@v3 + with: + title: Update no_atomic.rs + body: | + Auto-generated by [create-pull-request][1] + [Please close and immediately reopen this pull request to run CI.][2] + + [1]: https://github.com/peter-evans/create-pull-request + [2]: https://github.com/peter-evans/create-pull-request/blob/HEAD/docs/concepts-guidelines.md#workarounds-to-trigger-further-workflow-runs + branch: update-no-atomic-rs + if: github.repository_owner == 'tokio-rs' && github.event_name == 'schedule' && steps.diff.outputs.success == 'false' fmt: runs-on: ubuntu-latest diff --git a/valuable/no_atomic.rs b/valuable/no_atomic.rs index 3c25155..6594d62 100644 --- a/valuable/no_atomic.rs +++ b/valuable/no_atomic.rs @@ -43,7 +43,6 @@ const NO_ATOMIC_64: &[&str] = &[ "riscv32gc-unknown-linux-gnu", "riscv32gc-unknown-linux-musl", "riscv32imac-unknown-none-elf", - "riscv32imc-esp-espidf", "thumbv7em-none-eabi", "thumbv7em-none-eabihf", "thumbv7m-none-eabi",