-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Changed type transition steps in impls * Added derived type generics support * Split integration tests * Added CI jobs * Added .rustfmt.toml * Updated docs * Bump to 1.0.0 release
- Loading branch information
Showing
27 changed files
with
953 additions
and
512 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# yaml-language-server: $schema=./main.yaml | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
pull_request: | ||
branches: ["main"] | ||
|
||
env: | ||
RUST_TOOLCHAIN: 1.74.0 | ||
|
||
jobs: | ||
format: | ||
name: Format | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Setup Rust toolchain | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: nightly | ||
override: true | ||
components: rustfmt | ||
|
||
- uses: actions-rs/cargo@v1 | ||
with: | ||
command: fmt | ||
args: -- --check | ||
|
||
clippy: | ||
name: Clippy | ||
needs: format | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Setup Rust toolchain | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
override: true | ||
components: clippy | ||
|
||
- uses: Swatinem/rust-cache@v2 | ||
|
||
- uses: actions-rs/cargo@v1 | ||
with: | ||
command: clippy | ||
args: --tests | ||
env: | ||
RUSTFLAGS: -D warnings | ||
|
||
|
||
tests: | ||
name: Tests | ||
needs: clippy | ||
runs-on: ubuntu-20.04 | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Setup Rust toolchain | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: ${{ env.RUST_TOOLCHAIN }} | ||
override: true | ||
|
||
- uses: Swatinem/rust-cache@v2 | ||
|
||
- name: Run tests | ||
run: cargo test |
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,14 @@ | ||
# rust-analyzer can be configured with nightly rustfmt | ||
# i.e. for vscode in settings.json: | ||
# "rust-analyzer.rustfmt.extraArgs": [ | ||
# "+nightly" | ||
# ], | ||
unstable_features = true | ||
group_imports = "StdExternalCrate" | ||
imports_granularity = "Crate" | ||
format_code_in_doc_comments = true | ||
format_macro_bodies = true | ||
format_macro_matchers = true | ||
format_strings = true | ||
comment_width = 100 | ||
wrap_comments = true |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,53 @@ | ||
mod try_from; | ||
mod try_into; | ||
|
||
pub use try_from::TransitiveTryFrom; | ||
pub use try_into::TransitiveTryInto; | ||
use syn::{ | ||
parse::{Parse, ParseStream}, | ||
punctuated::Punctuated, | ||
spanned::Spanned, | ||
Error as SynError, Expr, Meta, Path, Result as SynResult, Token, | ||
}; | ||
pub use try_from::TryTransitionFrom; | ||
pub use try_into::TryTransitionInto; | ||
|
||
/// A path list that may contain a custom error type. | ||
pub struct FalliblePathList { | ||
path_list: Vec<Path>, | ||
error: Option<Path>, | ||
} | ||
|
||
impl Parse for FalliblePathList { | ||
fn parse(input: ParseStream) -> SynResult<Self> { | ||
let meta_list = Punctuated::<Meta, Token![,]>::parse_terminated(input)?; | ||
|
||
let mut path_list = Vec::with_capacity(meta_list.len()); | ||
let mut error = None; | ||
|
||
let mut iter = meta_list.into_iter().peekable(); | ||
|
||
while let Some(meta) = iter.next() { | ||
// If this is not the last element then it's definitely part of the path list | ||
if iter.peek().is_some() { | ||
match meta { | ||
Meta::Path(path) => path_list.push(path), | ||
_ => return Err(SynError::new(meta.span(), "invalid value in path list")), | ||
}; | ||
} else { | ||
// We reached the last element which could be the custom error type | ||
match meta { | ||
// Just a regular type path in the conversion path | ||
Meta::Path(p) => path_list.push(p), | ||
// Custom error, but must check that it's a type path | ||
Meta::NameValue(n) if n.path.is_ident("error") => match n.value { | ||
Expr::Path(p) => error = Some(p.path), | ||
_ => return Err(SynError::new(n.value.span(), "error must be a type")), | ||
}, | ||
_ => return Err(SynError::new(meta.span(), "invalid value in path list")), | ||
} | ||
} | ||
} | ||
|
||
let output = Self { path_list, error }; | ||
Ok(output) | ||
} | ||
} |
Oops, something went wrong.