-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for
sv::features
attribute. (#446)
Remove `sv_replies` feature as it does not make the change non breaking.
- Loading branch information
Showing
21 changed files
with
135 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use proc_macro_error::emit_error; | ||
use syn::parse::{Parse, ParseStream, Parser}; | ||
use syn::{Error, Ident, MetaList, Result, Token}; | ||
|
||
/// Type wrapping data parsed from `sv::features` attribute. | ||
#[derive(Debug, Default)] | ||
pub struct SylviaFeatures { | ||
/// Enables better dispatching and deserialization for replies. | ||
pub replies: bool, | ||
} | ||
|
||
impl SylviaFeatures { | ||
pub fn new(attr: &MetaList) -> Result<Self> { | ||
SylviaFeatures::parse | ||
.parse2(attr.tokens.clone()) | ||
.map_err(|err| { | ||
emit_error!(err.span(), err); | ||
err | ||
}) | ||
} | ||
} | ||
|
||
impl Parse for SylviaFeatures { | ||
fn parse(input: ParseStream) -> Result<Self> { | ||
let mut features = Self::default(); | ||
|
||
while !input.is_empty() { | ||
let feature: Ident = input.parse()?; | ||
match feature.to_string().as_str() { | ||
"replies" => features.replies = true, | ||
_ => { | ||
return Err(Error::new( | ||
feature.span(), | ||
"Invalid feature.\n= note: Expected `#[sv::features(replies)];`.\n", | ||
)) | ||
} | ||
} | ||
if !input.peek(Token![,]) { | ||
break; | ||
} | ||
let _: Token![,] = input.parse()?; | ||
} | ||
|
||
Ok(features) | ||
} | ||
} |
This file contains 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 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
Oops, something went wrong.