Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement TypeInfo for Arc #180

Merged
merged 5 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.7.0] - 2023-05-15

### Added
- `TypeInfo` is now implemented for `Arc` [(#180)](https://github.com/paritytech/scale-info/pull/180)

## [2.6.0] - 2023-04-26

### Added
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "scale-info"
version = "2.6.0"
version = "2.7.0"
authors = ["Parity Technologies <[email protected]>"]
edition = "2021"
rust-version = "1.60.0"
Expand Down
12 changes: 12 additions & 0 deletions src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use crate::prelude::{
RangeInclusive,
},
string::String,
sync::Arc,
vec::Vec,
};

Expand Down Expand Up @@ -279,6 +280,17 @@ where
}
}

impl<T> TypeInfo for Arc<T>
where
T: TypeInfo + ?Sized + 'static,
{
type Identity = T;

fn type_info() -> Type {
Self::Identity::type_info()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to revisit the idea of adding some extra information about transparent wrapper types like this, e.g. for Box to avoid https://github.com/paritytech/subxt/blob/c08eb6c8f1ae1ea61964196733008cc3a4bfb627/codegen/src/types/composite_def.rs#L307

}
}

impl<T> TypeInfo for &T
where
T: TypeInfo + ?Sized + 'static,
Expand Down
2 changes: 2 additions & 0 deletions src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ cfg_if! {
num,
ops,
string,
sync,
vec,
};
} else {
Expand All @@ -46,6 +47,7 @@ cfg_if! {
collections,
format,
string,
sync,
vec,
};

Expand Down
2 changes: 1 addition & 1 deletion test_suite/tests/ui/fail_unions.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ error[E0277]: the trait bound `Commonwealth: TypeInfo` is not satisfied
(A, B, C, D)
(A, B, C, D, E)
(A, B, C, D, E, F)
and 53 others
and $N others
note: required by a bound in `assert_type_info`
--> tests/ui/fail_unions.rs:11:24
|
Expand Down