MCPcopy Index your code
hub / github.com/TedDriggs/from_variants

github.com/TedDriggs/from_variants @v1.0.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.0.2 ↗ · + Follow
28 symbols 42 edges 8 files 3 documented · 11%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Build Status Latest Version

Newtype Variant Conversions

Rust macro crate to automatically generate conversions from variant types into the target enum.

This crate requires Rust 1.45 or above to compile on stable.

Examples

use from_variants::FromVariants;

#[derive(Debug, Clone, PartialEq, Eq, FromVariants)]
pub enum Lorem {
    Str(String),
    Num(u16),
}

fn main() {
    assert_eq!(Lorem::Num(10), Lorem::from(10));
}

You can skip variants to avoid type collisions:

use from_variants::FromVariants;

#[derive(Debug, Clone, PartialEq, Eq, FromVariants)]
pub enum Ipsum {
    Hello(String),

    #[from_variants(skip)]
    Goodbye(String),
}

fn main() {
    assert_eq!(Ipsum::Hello("John".to_string()), Ipsum::from("John".to_string()));
}

Features

  • Variant opt-out: To skip a variant, add #[from_variants(skip)] to that variant.
  • Conversion opt-in: Use #[from_variants(into)] on an enum or variant to generate conversions that will automatically convert - for example, accepting a &str for a String variant. This must be used sparingly to avoid generating conflicting impls.
  • no_std support: Generated conversions do not depend on the standard library.

Core symbols most depended-on inside this repo

assert_generates
called by 4
from_variants_impl/src/from_impl.rs
is_enabled
called by 2
from_variants_impl/src/parser.rs
as_impls
called by 1
from_variants_impl/src/parser.rs
ty
called by 1
from_variants_impl/src/parser.rs
generate_into_ty_param
called by 1
from_variants_impl/src/from_impl.rs
build_converters
called by 1
from_variants_impl/src/lib.rs
from
called by 0
from_variants_impl/src/parser.rs
validate
called by 0
from_variants_impl/src/parser.rs

Shape

Function 13
Method 7
Enum 5
Class 3

Languages

Rust100%

Modules by API surface

from_variants_impl/src/from_impl.rs8 symbols
from_variants_impl/src/parser.rs7 symbols
examples/hand_written.rs4 symbols
tests/no_std.rs3 symbols
tests/e2e.rs2 symbols
from_variants_impl/src/lib.rs2 symbols
examples/generated.rs2 symbols

For agents

$ claude mcp add from_variants \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page