lens implemented in rust

Overview

Overview

This project contains two crates: lens-rs and lens-rs_derive. The lens-rs provide some definitions of lens. The lens-rs_derive provide the macro to derive lens for data types.

Comments
  • `#[derive(Optic)]` is shown in README but not actually available

    `#[derive(Optic)]` is shown in README but not actually available

    derive_optic was removed but the README still references it.

    https://github.com/TOETOE55/lens-rs/commit/3c19d0d2516dd0ca128972bcd194da861cf0ae5d#diff-dc4a22e0b81ffbabfdb6f61ae197ca2f0a406ddf9141d14e930b56b5df7b3a74R41

    How can we have optics on struct fields now?

    I know this crate is very new, but I'm excited about it. Nice work!

    opened by maackle 5
  • Looks like dyn_optics.rs needs to be added?

    Looks like dyn_optics.rs needs to be added?

    When I build I see

       Compiling lens-rs v0.3.2 (.../repos/lens-rs/lens-rs)
     error[E0583]: file not found for module `dyn_optics`
       --> lens-rs/src/lib.rs:210:1
        |
    210 | pub mod dyn_optics;
        | ^^^^^^^^^^^^^^^^^^^
        |
        = help: to create the module `dyn_optics`, create file "lens-rs/src/dyn_optics.rs" or "lens-rs/src/dyn_optics/mod.rs"
    
    

    It looks like the recent merge added line 210 above, but not the dyn_optics.rs file. Thanks for this crate!

    opened by windwardly 4
  • Example can't pass build with version 0.3.2

    Example can't pass build with version 0.3.2

    rust version is rustc 1.57.0 (f1edd0429 2021-11-29) With example as blow

    
    #[derive(Copy, Clone, Debug, Review, Prism)]
    enum Either<L, R> {
        #[optic]
        Left(L), // generate optics::Left
        #[optic]
        Right(R), // generate optics::Right
    }
    
    #[derive(Copy, Clone, Debug, Lens)]
    struct Tuple<A, B>(#[optic] A, #[optic] B); 
    // use optics::_0 or optics::_1 to access it
    
    #[derive(Copy, Clone, Debug, Lens)]
    struct Foo<A, B> {
        #[optic]
        a: A, // generate optics::a
        #[optic]
        b: B, // generate optics::b
    }
    
    
    #[derive(Clone, Debug, Lens)]
    struct Bar {
        #[optic]
        a: String, // generate optics::a, same as above
        #[optic]
        c: i32,    // generate optics::c
    }```
    
    get error 
    
    ```error[E0412]: cannot find type `Left` in module `lens_rs::optics`
      --> src/domain/mod.rs:15:5
       |
    15 |     Left(L), // generate optics::Left
       |     ^^^^ not found in `lens_rs::optics`
       |
    help: there is an enum variant `core::fmt::Alignment::Left` and 11 others; try using the variant's enum
       |
    12 | #[derive(Copy, Clone, Debug, core::fmt::Alignment, Prism)]
       |                              ~~~~~~~~~~~~~~~~~~~~
    12 | #[derive(Copy, Clone, Debug, core::fmt::rt::v1::Alignment, Prism)]
       |                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    12 | #[derive(Copy, Clone, Debug, crate::domain::Either, Prism)]
       |                              ~~~~~~~~~~~~~~~~~~~~~
    12 | #[derive(Copy, Clone, Debug, futures::future::Either, Prism)]
       |                              ~~~~~~~~~~~~~~~~~~~~~~~
         and 7 other candidates
    
    error[E0412]: cannot find type `Right` in module `lens_rs::optics`
      --> src/domain/mod.rs:17:5
       |
    17 |     Right(R), // generate optics::Right
       |     ^^^^^ not found in `lens_rs::optics`
       |
    help: there is an enum variant `core::fmt::Alignment::Right` and 11 others; try using the variant's enum
       |
    12 | #[derive(Copy, Clone, Debug, core::fmt::Alignment, Prism)]
       |                              ~~~~~~~~~~~~~~~~~~~~
    12 | #[derive(Copy, Clone, Debug, core::fmt::rt::v1::Alignment, Prism)]
       |                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    12 | #[derive(Copy, Clone, Debug, crate::domain::Either, Prism)]
       |                              ~~~~~~~~~~~~~~~~~~~~~
    12 | #[derive(Copy, Clone, Debug, futures::future::Either, Prism)]
       |                              ~~~~~~~~~~~~~~~~~~~~~~~
         and 7 other candidates
    
    error[E0412]: cannot find type `Left` in module `lens_rs::optics`
      --> src/domain/mod.rs:15:5
       |
    15 |     Left(L), // generate optics::Left
       |     ^^^^ not found in `lens_rs::optics`
       |
    help: there is an enum variant `core::fmt::Alignment::Left` and 11 others; try using the variant's enum
       |
    12 | #[derive(Copy, Clone, Debug, Review, core::fmt::Alignment)]
       |                                      ~~~~~~~~~~~~~~~~~~~~
    12 | #[derive(Copy, Clone, Debug, Review, core::fmt::rt::v1::Alignment)]
       |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    12 | #[derive(Copy, Clone, Debug, Review, crate::domain::Either)]
       |                                      ~~~~~~~~~~~~~~~~~~~~~
    12 | #[derive(Copy, Clone, Debug, Review, futures::future::Either)]
       |                                      ~~~~~~~~~~~~~~~~~~~~~~~
         and 7 other candidates
    
    error[E0412]: cannot find type `Right` in module `lens_rs::optics`
      --> src/domain/mod.rs:17:5
       |
    17 |     Right(R), // generate optics::Right
       |     ^^^^^ not found in `lens_rs::optics`
       |
    help: there is an enum variant `core::fmt::Alignment::Right` and 11 others; try using the variant's enum
       |
    12 | #[derive(Copy, Clone, Debug, Review, core::fmt::Alignment)]
       |                                      ~~~~~~~~~~~~~~~~~~~~
    12 | #[derive(Copy, Clone, Debug, Review, core::fmt::rt::v1::Alignment)]
       |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    12 | #[derive(Copy, Clone, Debug, Review, crate::domain::Either)]
       |                                      ~~~~~~~~~~~~~~~~~~~~~
    12 | #[derive(Copy, Clone, Debug, Review, futures::future::Either)]
       |                                      ~~~~~~~~~~~~~~~~~~~~~~~
         and 7 other candidates
    
    error[E0412]: cannot find type `a` in module `lens_rs::optics`
      --> src/domain/mod.rs:27:5
       |
    27 |     a: A, // generate optics::a
       |     ^ not found in `lens_rs::optics`
    
    error[E0412]: cannot find type `b` in module `lens_rs::optics`
      --> src/domain/mod.rs:29:5
       |
    29 |     b: B, // generate optics::b
       |     ^ not found in `lens_rs::optics`
    
    error[E0412]: cannot find type `a` in module `lens_rs::optics`
      --> src/domain/mod.rs:36:5
       |
    36 |     a: String, // generate optics::a, same as above
       |     ^ not found in `lens_rs::optics`
    
    error[E0412]: cannot find type `c` in module `lens_rs::optics`
      --> src/domain/mod.rs:38:5
       |
    38 |     c: i32,    // generate optics::c
       |     ^ not found in `lens_rs::optics`
    
    warning: unused import: `ChildStdin`
     --> src/domain/command.rs:3:34
      |
    3 | use std::process::{Stdio,Command,ChildStdin};
      |                                  ^^^^^^^^^^
      |
      = note: `#[warn(unused_imports)]` on by default
    
    warning: unused import: `super::validate::validate_raw`
     --> src/domain/model.rs:9:5
      |
    9 | use super::validate::validate_raw;
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
    error[E0207]: the type parameter `__Rv` is not constrained by the impl trait, self type, or predicates
      --> src/domain/mod.rs:12:30
       |
    12 | #[derive(Copy, Clone, Debug, Review, Prism)]
       |                              ^^^^^^ unconstrained type parameter
       |
       = note: this error originates in the derive macro `Review` (in Nightly builds, run with -Z macro-backtrace for more info)
    
    error[E0207]: the type parameter `__Tr` is not constrained by the impl trait, self type, or predicates
      --> src/domain/mod.rs:12:38
       |
    12 | #[derive(Copy, Clone, Debug, Review, Prism)]
       |                                      ^^^^^ unconstrained type parameter
       |
       = note: this error originates in the derive macro `Prism` (in Nightly builds, run with -Z macro-backtrace for more info)
    
    error[E0207]: the type parameter `__Pm` is not constrained by the impl trait, self type, or predicates
      --> src/domain/mod.rs:12:38
       |
    12 | #[derive(Copy, Clone, Debug, Review, Prism)]
       |                                      ^^^^^ unconstrained type parameter
       |
       = note: this error originates in the derive macro `Prism` (in Nightly builds, run with -Z macro-backtrace for more info)
    
    error[E0207]: the type parameter `__Tr` is not constrained by the impl trait, self type, or predicates
      --> src/domain/mod.rs:24:30
       |
    24 | #[derive(Copy, Clone, Debug, Lens)]
       |                              ^^^^ unconstrained type parameter
       |
       = note: this error originates in the derive macro `Lens` (in Nightly builds, run with -Z macro-backtrace for more info)
    
    error[E0207]: the type parameter `__Pm` is not constrained by the impl trait, self type, or predicates
      --> src/domain/mod.rs:24:30
       |
    24 | #[derive(Copy, Clone, Debug, Lens)]
       |                              ^^^^ unconstrained type parameter
       |
       = note: this error originates in the derive macro `Lens` (in Nightly builds, run with -Z macro-backtrace for more info)
    
    error[E0207]: the type parameter `__Ls` is not constrained by the impl trait, self type, or predicates
      --> src/domain/mod.rs:24:30
       |
    24 | #[derive(Copy, Clone, Debug, Lens)]
       |                              ^^^^ unconstrained type parameter
       |
       = note: this error originates in the derive macro `Lens` (in Nightly builds, run with -Z macro-backtrace for more info)
    
    error[E0207]: the type parameter `__Tr` is not constrained by the impl trait, self type, or predicates
      --> src/domain/mod.rs:33:24
       |
    33 | #[derive(Clone, Debug, Lens)]
       |                        ^^^^ unconstrained type parameter
       |
       = note: this error originates in the derive macro `Lens` (in Nightly builds, run with -Z macro-backtrace for more info)
    
    error[E0207]: the type parameter `__Pm` is not constrained by the impl trait, self type, or predicates
      --> src/domain/mod.rs:33:24
       |
    33 | #[derive(Clone, Debug, Lens)]
       |                        ^^^^ unconstrained type parameter
       |
       = note: this error originates in the derive macro `Lens` (in Nightly builds, run with -Z macro-backtrace for more info)
    
    error[E0207]: the type parameter `__Ls` is not constrained by the impl trait, self type, or predicates
      --> src/domain/mod.rs:33:24
       |
    33 | #[derive(Clone, Debug, Lens)]
       |                        ^^^^ unconstrained type parameter
    

    Can you please give a example project can pass build.

    opened by JulianZhang 3
  • Test errors version 0.3.2

    Test errors version 0.3.2

    I get the following test errors when i try to do cargo test:

    failures: src/lib.rs - (line 103) src/lib.rs - (line 115) src/lib.rs - (line 131) src/lib.rs - (line 182) src/lib.rs - (line 222) src/lib.rs - (line 35) src/lib.rs - (line 45) src/lib.rs - (line 54) src/lib.rs - (line 63) src/lib.rs - (line 72) src/lib.rs - (line 87) src/lib.rs - Optics (line 222) src/lib.rs - optics (line 222) src/traits.rs - traits::prism (line 56) src/traits.rs - traits::traversal (line 24)

    opened by ehoeve 3
  • derives lens traits for structx

    derives lens traits for structx

    1. Specify path for the dependency of lens-rs_derive in lens-rs's Cargo.toml.
      According to the [cargo book](https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html?highlight=specify%20depend#multiple-locations):
      > One example where this can be useful is when you have split up a library into multiple packages within the same workspace. You can then use path dependencies to point to the local packages within the workspace to use the local version during development, and then use the crates.io version once it is published.
    
    2. Crate lens-rs_derive adds experimental support for deriving lens_rs::{Optic, Review, Prism, Lens} for [structx](https://github.com/oooutlk/structx/tree/structx_derives_lens).
    
    opened by oooutlk 0
Owner
Danube
Danube
Python module implemented in Rust for counting the number of one bits in a numpy array.

bit-counter Package for counting the number of one bits in a numpy array of uint8 values. Implemented as a Python module using Rust, providing high pe

Andrew MacDonald 3 Jul 9, 2022
A Rust crate for automatically generating C header files from Rust source file.

Please be aware that this crate is no longer actively maintained, please look into the much more feature rich cbindgen instead. rusty-cheddar rusty-ch

Sean Marshallsay 190 Nov 12, 2022
Rust-ffi-guide - A guide for doing FFI using Rust

Using unsafe for Fun and Profit A guide to traversing the FFI boundary between Rust and other languages. A rendered version is available here. This gu

Michael Bryan 261 Dec 1, 2022
Rust library for build scripts to compile C/C++ code into a Rust library

A library to compile C/C++/assembly into a Rust library/application.

Alex Crichton 1.3k Dec 21, 2022
Rust based WASM/JS bindings for ur-rust

ur-wasm-js WASM/JS bindings for the ur-rust rust library Getting started Installation Either build the library yourself with wasm-pack or install for

Lightning Digital Entertainment 5 Feb 28, 2024
A project for generating C bindings from Rust code

cbindgen   Read the full user docs here! cbindgen creates C/C++11 headers for Rust libraries which expose a public C API. While you could do this by h

Ryan Hunt 1.7k Jan 3, 2023
Automatically generates Rust FFI bindings to C (and some C++) libraries.

bindgen bindgen automatically generates Rust FFI bindings to C (and some C++) libraries. For example, given the C header doggo.h: typedef struct Doggo

The Rust Programming Language 3.2k Jan 4, 2023
Safe interop between Rust and C++

CXX — safe FFI between Rust and C++ This library provides a safe mechanism for calling C++ code from Rust and Rust code from C++, not subject to the m

David Tolnay 4.4k Jan 7, 2023
Safe Rust bridge for creating Erlang NIF functions

Rustler Documentation | Getting Started | Example Rustler is a library for writing Erlang NIFs in safe Rust code. That means there should be no ways t

Rusterlium 3.5k Jan 7, 2023
Bridge the gap between Haskell and Rust

Curryrs Curryrs (a play on the name of Haskell Curry, rs for Rust libraries, and it's pronunciation couriers) is a library for providing easy to use b

Michael Gattozzi 296 Oct 18, 2022
Rust in Haskell FFI Example

Provides an example for using Rust in Haskell. To use this you'll need cargo, rustc, cabal and GHC installed. To execute the example run the following

Michael Gattozzi 21 Oct 1, 2022
Run Java code from Rust!

Java Native Interface Bindings for Rust This library provides complete FFI bindings to the Java Native Interface, as well as a safe and intuitive wrap

Ben Anderson 66 Nov 28, 2022
Embedding Rust in Java

Java/Rust Example An example project showing how to call into Rust code from Java. OSX Linux Windows Requirements Java 7+ Rust (tested with 1.0, night

drrb 318 Jan 1, 2023
Rust-JDBC bindings

jdbc A Rust library that allows you to use JDBC and JDBC drivers. Usage First, add the following to your Cargo.toml: [dependencies] jdbc = "0.1" Next,

Aurora 18 Feb 9, 2022
Lua 5.3 bindings for Rust

rust-lua53 Aims to be complete Rust bindings for Lua 5.3 and beyond. Currently, master is tracking Lua 5.3.3. Requires a Unix-like environment. On Win

J.C. Moyer 150 Dec 14, 2022
Safe Rust bindings to Lua 5.1

rust-lua Copyright 2014 Lily Ballard Description This is a set of Rust bindings to Lua 5.1. The goal is to provide a (relatively) safe interface to Lu

Lily Ballard 124 Jan 5, 2023
Zero-cost high-level lua 5.3 wrapper for Rust

td_rlua This library is a high-level binding for Lua 5.3. You don't have access to the Lua stack, all you can do is read/write variables (including ca

null 47 May 4, 2022
Rust library to interface with Lua

hlua This library is a high-level binding for Lua 5.2. You don't have access to the Lua stack, all you can do is read/write variables (including callb

Pierre Krieger 488 Dec 26, 2022
mruby safe bindings for Rust

mrusty. mruby safe bindings for Rust mrusty lets you: run Ruby 1.9 files with a very restricted API (without having to install Ruby) reflect Rust stru

Anima 200 Oct 12, 2022