-
Notifications
You must be signed in to change notification settings - Fork 82
Remove dependency on rustfmt
installation for consumers
#221
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8be8037
Add `rustfmt` and `prettyplease` features
mbrobbel cced301
Remove impl `ToString` for `TypeSpace` and `rustfmt-wrapper` dependency
mbrobbel 103506e
Use `rustfmt` instead of `prettyplease`
mbrobbel c1944da
Add changelog entry
mbrobbel e7e2bdb
Fix code blocks
mbrobbel 721a5f1
Fix path
mbrobbel 9702468
Merge branch 'main' into rustfmt
mbrobbel 11e7f58
Reflect removal of `ToString` in `cargo-typify`
mbrobbel 5af168c
Remove `syn` from `typify-test` build deps
mbrobbel 75c64fe
Use `prettyplease` in examples and add Formatting section to README
mbrobbel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,233 +1 @@ | ||
mod types { | ||
#[derive( | ||
Clone, Debug, Deserialize, Eq, Hash, JsonSchema, Ord, PartialEq, PartialOrd, Serialize, | ||
)] | ||
pub struct AllTheTraits { | ||
pub ok: String, | ||
} | ||
impl From<&AllTheTraits> for AllTheTraits { | ||
fn from(value: &AllTheTraits) -> Self { | ||
value.clone() | ||
} | ||
} | ||
impl AllTheTraits { | ||
pub fn builder() -> builder::AllTheTraits { | ||
builder::AllTheTraits::default() | ||
} | ||
} | ||
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] | ||
pub struct CompoundType { | ||
pub value1: String, | ||
pub value2: u64, | ||
} | ||
impl From<&CompoundType> for CompoundType { | ||
fn from(value: &CompoundType) -> Self { | ||
value.clone() | ||
} | ||
} | ||
impl CompoundType { | ||
pub fn builder() -> builder::CompoundType { | ||
builder::CompoundType::default() | ||
} | ||
} | ||
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] | ||
pub struct Pair { | ||
#[serde(default = "defaults::pair_a")] | ||
pub a: StringEnum, | ||
#[serde(default = "defaults::pair_b")] | ||
pub b: StringEnum, | ||
} | ||
impl From<&Pair> for Pair { | ||
fn from(value: &Pair) -> Self { | ||
value.clone() | ||
} | ||
} | ||
impl Pair { | ||
pub fn builder() -> builder::Pair { | ||
builder::Pair::default() | ||
} | ||
} | ||
#[derive( | ||
Clone, Copy, Debug, Deserialize, Eq, Hash, JsonSchema, Ord, PartialEq, PartialOrd, Serialize, | ||
)] | ||
pub enum StringEnum { | ||
One, | ||
Two, | ||
BuckleMyShoe, | ||
} | ||
impl From<&StringEnum> for StringEnum { | ||
fn from(value: &StringEnum) -> Self { | ||
value.clone() | ||
} | ||
} | ||
impl ToString for StringEnum { | ||
fn to_string(&self) -> String { | ||
match *self { | ||
Self::One => "One".to_string(), | ||
Self::Two => "Two".to_string(), | ||
Self::BuckleMyShoe => "BuckleMyShoe".to_string(), | ||
} | ||
} | ||
} | ||
impl std::str::FromStr for StringEnum { | ||
type Err = &'static str; | ||
fn from_str(value: &str) -> Result<Self, &'static str> { | ||
match value { | ||
"One" => Ok(Self::One), | ||
"Two" => Ok(Self::Two), | ||
"BuckleMyShoe" => Ok(Self::BuckleMyShoe), | ||
_ => Err("invalid value"), | ||
} | ||
} | ||
} | ||
impl std::convert::TryFrom<&str> for StringEnum { | ||
type Error = &'static str; | ||
fn try_from(value: &str) -> Result<Self, &'static str> { | ||
value.parse() | ||
} | ||
} | ||
impl std::convert::TryFrom<&String> for StringEnum { | ||
type Error = &'static str; | ||
fn try_from(value: &String) -> Result<Self, &'static str> { | ||
value.parse() | ||
} | ||
} | ||
impl std::convert::TryFrom<String> for StringEnum { | ||
type Error = &'static str; | ||
fn try_from(value: String) -> Result<Self, &'static str> { | ||
value.parse() | ||
} | ||
} | ||
mod builder { | ||
pub struct AllTheTraits { | ||
ok: Result<String, String>, | ||
} | ||
impl Default for AllTheTraits { | ||
fn default() -> Self { | ||
Self { | ||
ok: Err("no value supplied for ok".to_string()), | ||
} | ||
} | ||
} | ||
impl AllTheTraits { | ||
pub fn ok<T>(mut self, value: T) -> Self | ||
where | ||
T: std::convert::TryInto<String>, | ||
T::Error: std::fmt::Display, | ||
{ | ||
self.ok = value | ||
.try_into() | ||
.map_err(|e| format!("error converting supplied value for ok: {}", e)); | ||
self | ||
} | ||
} | ||
impl std::convert::TryFrom<AllTheTraits> for super::AllTheTraits { | ||
type Error = String; | ||
fn try_from(value: AllTheTraits) -> Result<Self, String> { | ||
Ok(Self { ok: value.ok? }) | ||
} | ||
} | ||
pub struct CompoundType { | ||
value1: Result<String, String>, | ||
value2: Result<u64, String>, | ||
} | ||
impl Default for CompoundType { | ||
fn default() -> Self { | ||
Self { | ||
value1: Err("no value supplied for value1".to_string()), | ||
value2: Err("no value supplied for value2".to_string()), | ||
} | ||
} | ||
} | ||
impl CompoundType { | ||
pub fn value1<T>(mut self, value: T) -> Self | ||
where | ||
T: std::convert::TryInto<String>, | ||
T::Error: std::fmt::Display, | ||
{ | ||
self.value1 = value | ||
.try_into() | ||
.map_err(|e| format!("error converting supplied value for value1: {}", e)); | ||
self | ||
} | ||
pub fn value2<T>(mut self, value: T) -> Self | ||
where | ||
T: std::convert::TryInto<u64>, | ||
T::Error: std::fmt::Display, | ||
{ | ||
self.value2 = value | ||
.try_into() | ||
.map_err(|e| format!("error converting supplied value for value2: {}", e)); | ||
self | ||
} | ||
} | ||
impl std::convert::TryFrom<CompoundType> for super::CompoundType { | ||
type Error = String; | ||
fn try_from(value: CompoundType) -> Result<Self, String> { | ||
Ok(Self { | ||
value1: value.value1?, | ||
value2: value.value2?, | ||
}) | ||
} | ||
} | ||
pub struct Pair { | ||
a: Result<super::StringEnum, String>, | ||
b: Result<super::StringEnum, String>, | ||
} | ||
impl Default for Pair { | ||
fn default() -> Self { | ||
Self { | ||
a: Ok(super::defaults::pair_a()), | ||
b: Ok(super::defaults::pair_b()), | ||
} | ||
} | ||
} | ||
impl Pair { | ||
pub fn a<T>(mut self, value: T) -> Self | ||
where | ||
T: std::convert::TryInto<super::StringEnum>, | ||
T::Error: std::fmt::Display, | ||
{ | ||
self.a = value | ||
.try_into() | ||
.map_err(|e| format!("error converting supplied value for a: {}", e)); | ||
self | ||
} | ||
pub fn b<T>(mut self, value: T) -> Self | ||
where | ||
T: std::convert::TryInto<super::StringEnum>, | ||
T::Error: std::fmt::Display, | ||
{ | ||
self.b = value | ||
.try_into() | ||
.map_err(|e| format!("error converting supplied value for b: {}", e)); | ||
self | ||
} | ||
} | ||
impl std::convert::TryFrom<Pair> for super::Pair { | ||
type Error = String; | ||
fn try_from(value: Pair) -> Result<Self, String> { | ||
Ok(Self { | ||
a: value.a?, | ||
b: value.b?, | ||
}) | ||
} | ||
} | ||
} | ||
mod defaults { | ||
pub(super) fn pair_a() -> super::StringEnum { | ||
super::StringEnum::One | ||
} | ||
pub(super) fn pair_b() -> super::StringEnum { | ||
super::StringEnum::Two | ||
} | ||
} | ||
} | ||
pub fn do_stuff( | ||
body: &types::CompoundType, | ||
string: &str, | ||
opt_int: Option<u32>, | ||
strenum: types::StringEnum, | ||
) -> types::CompoundType { | ||
todo!() | ||
} | ||
mod types { # [derive (Clone , Debug , Deserialize , Eq , Hash , JsonSchema , Ord , PartialEq , PartialOrd , Serialize)] pub struct AllTheTraits { pub ok : String , } impl From < & AllTheTraits > for AllTheTraits { fn from (value : & AllTheTraits) -> Self { value . clone () } } impl AllTheTraits { pub fn builder () -> builder :: AllTheTraits { builder :: AllTheTraits :: default () } } # [derive (Clone , Debug , Deserialize , JsonSchema , Serialize)] pub struct CompoundType { pub value1 : String , pub value2 : u64 , } impl From < & CompoundType > for CompoundType { fn from (value : & CompoundType) -> Self { value . clone () } } impl CompoundType { pub fn builder () -> builder :: CompoundType { builder :: CompoundType :: default () } } # [derive (Clone , Debug , Deserialize , JsonSchema , Serialize)] pub struct Pair { # [serde (default = "defaults::pair_a")] pub a : StringEnum , # [serde (default = "defaults::pair_b")] pub b : StringEnum , } impl From < & Pair > for Pair { fn from (value : & Pair) -> Self { value . clone () } } impl Pair { pub fn builder () -> builder :: Pair { builder :: Pair :: default () } } # [derive (Clone , Copy , Debug , Deserialize , Eq , Hash , JsonSchema , Ord , PartialEq , PartialOrd , Serialize)] pub enum StringEnum { One , Two , BuckleMyShoe , } impl From < & StringEnum > for StringEnum { fn from (value : & StringEnum) -> Self { value . clone () } } impl ToString for StringEnum { fn to_string (& self) -> String { match * self { Self :: One => "One" . to_string () , Self :: Two => "Two" . to_string () , Self :: BuckleMyShoe => "BuckleMyShoe" . to_string () , } } } impl std :: str :: FromStr for StringEnum { type Err = & 'static str ; fn from_str (value : & str) -> Result < Self , & 'static str > { match value { "One" => Ok (Self :: One) , "Two" => Ok (Self :: Two) , "BuckleMyShoe" => Ok (Self :: BuckleMyShoe) , _ => Err ("invalid value") , } } } impl std :: convert :: TryFrom < & str > for StringEnum { type Error = & 'static str ; fn try_from (value : & str) -> Result < Self , & 'static str > { value . parse () } } impl std :: convert :: TryFrom < & String > for StringEnum { type Error = & 'static str ; fn try_from (value : & String) -> Result < Self , & 'static str > { value . parse () } } impl std :: convert :: TryFrom < String > for StringEnum { type Error = & 'static str ; fn try_from (value : String) -> Result < Self , & 'static str > { value . parse () } } mod builder { pub struct AllTheTraits { ok : Result < String , String > , } impl Default for AllTheTraits { fn default () -> Self { Self { ok : Err ("no value supplied for ok" . to_string ()) , } } } impl AllTheTraits { pub fn ok < T > (mut self , value : T) -> Self where T : std :: convert :: TryInto < String > , T :: Error : std :: fmt :: Display , { self . ok = value . try_into () . map_err (| e | format ! ("error converting supplied value for ok: {}" , e)) ; self } } impl std :: convert :: TryFrom < AllTheTraits > for super :: AllTheTraits { type Error = String ; fn try_from (value : AllTheTraits) -> Result < Self , String > { Ok (Self { ok : value . ok ? , }) } } pub struct CompoundType { value1 : Result < String , String > , value2 : Result < u64 , String > , } impl Default for CompoundType { fn default () -> Self { Self { value1 : Err ("no value supplied for value1" . to_string ()) , value2 : Err ("no value supplied for value2" . to_string ()) , } } } impl CompoundType { pub fn value1 < T > (mut self , value : T) -> Self where T : std :: convert :: TryInto < String > , T :: Error : std :: fmt :: Display , { self . value1 = value . try_into () . map_err (| e | format ! ("error converting supplied value for value1: {}" , e)) ; self } pub fn value2 < T > (mut self , value : T) -> Self where T : std :: convert :: TryInto < u64 > , T :: Error : std :: fmt :: Display , { self . value2 = value . try_into () . map_err (| e | format ! ("error converting supplied value for value2: {}" , e)) ; self } } impl std :: convert :: TryFrom < CompoundType > for super :: CompoundType { type Error = String ; fn try_from (value : CompoundType) -> Result < Self , String > { Ok (Self { value1 : value . value1 ? , value2 : value . value2 ? , }) } } pub struct Pair { a : Result < super :: StringEnum , String > , b : Result < super :: StringEnum , String > , } impl Default for Pair { fn default () -> Self { Self { a : Ok (super :: defaults :: pair_a ()) , b : Ok (super :: defaults :: pair_b ()) , } } } impl Pair { pub fn a < T > (mut self , value : T) -> Self where T : std :: convert :: TryInto < super :: StringEnum > , T :: Error : std :: fmt :: Display , { self . a = value . try_into () . map_err (| e | format ! ("error converting supplied value for a: {}" , e)) ; self } pub fn b < T > (mut self , value : T) -> Self where T : std :: convert :: TryInto < super :: StringEnum > , T :: Error : std :: fmt :: Display , { self . b = value . try_into () . map_err (| e | format ! ("error converting supplied value for b: {}" , e)) ; self } } impl std :: convert :: TryFrom < Pair > for super :: Pair { type Error = String ; fn try_from (value : Pair) -> Result < Self , String > { Ok (Self { a : value . a ? , b : value . b ? , }) } } } mod defaults { pub (super) fn pair_a () -> super :: StringEnum { super :: StringEnum :: One } pub (super) fn pair_b () -> super :: StringEnum { super :: StringEnum :: Two } } } pub fn do_stuff (body : & types :: CompoundType , string : & str , opt_int : Option < u32 > , strenum : types :: StringEnum ,) -> types :: CompoundType { todo ! () } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.