mirror of
https://github.com/enso-org/enso.git
synced 2024-12-23 19:21:54 +03:00
The prelude library, coming from basegl, in preparation for AST. (#342)
This commit is contained in:
parent
427e784663
commit
d1796345a4
@ -1,5 +1,6 @@
|
||||
[workspace]
|
||||
|
||||
members = [
|
||||
"common/rust/parser"
|
||||
"common/rust/parser",
|
||||
"common/rust/prelude"
|
||||
]
|
@ -10,7 +10,8 @@ crate-type = ["cdylib", "rlib"]
|
||||
[dependencies]
|
||||
failure = "0.1"
|
||||
matches = "0.1"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
prelude = { version = "0.1.0", path = "../prelude" }
|
||||
serde = { version = "1.0" , features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
shrinkwraprs = "0.2.1"
|
||||
wasm-bindgen = "0.2"
|
||||
|
@ -1,4 +1,4 @@
|
||||
use failure::Fail;
|
||||
use prelude::*;
|
||||
|
||||
// ============
|
||||
// == Parser ==
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::{api, api::IsParser};
|
||||
use failure::Fail;
|
||||
use prelude::*;
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
|
@ -1,16 +1,17 @@
|
||||
pub mod api;
|
||||
|
||||
use prelude::*;
|
||||
|
||||
mod jsclient;
|
||||
mod wsclient;
|
||||
|
||||
use std::ops::DerefMut;
|
||||
|
||||
/// Handle to a parser implementation.
|
||||
///
|
||||
/// Currently this component is implemented as a wrapper over parser written
|
||||
/// in Scala. Depending on compilation target (native or wasm) it uses either
|
||||
/// implementation provided by `wsclient` or `jsclient`.
|
||||
#[derive(shrinkwraprs::Shrinkwrap)]
|
||||
#[derive(Shrinkwrap)]
|
||||
#[shrinkwrap(mutable)]
|
||||
pub struct Parser(pub Box<dyn api::IsParser>);
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#![cfg(not(target_arch = "wasm32"))]
|
||||
|
||||
use failure::Fail;
|
||||
use std::default::Default;
|
||||
use prelude::*;
|
||||
|
||||
use websocket::{
|
||||
stream::sync::TcpStream, ClientBuilder, Message, OwnedMessage,
|
||||
};
|
||||
|
16
common/rust/prelude/Cargo.toml
Normal file
16
common/rust/prelude/Cargo.toml
Normal file
@ -0,0 +1,16 @@
|
||||
[package]
|
||||
name = "prelude"
|
||||
version = "0.1.0"
|
||||
authors = ["Wojciech Danilo <wojciech.danilo@luna-lang.org>"]
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
|
||||
[dependencies]
|
||||
failure = "0.1.5"
|
||||
derive_more = "0.15.0"
|
||||
shrinkwraprs = "0.2.1"
|
||||
itertools = "0.8"
|
||||
derivative = "1.0.3"
|
||||
num = "0.2.0"
|
||||
boolinator = "2.4.0"
|
50
common/rust/prelude/src/lib.rs
Normal file
50
common/rust/prelude/src/lib.rs
Normal file
@ -0,0 +1,50 @@
|
||||
#![feature(trait_alias)]
|
||||
|
||||
pub use boolinator::Boolinator;
|
||||
pub use core::{any::type_name, fmt::Debug};
|
||||
pub use derivative::Derivative;
|
||||
pub use derive_more::*;
|
||||
pub use failure::Fail;
|
||||
pub use itertools::Itertools;
|
||||
pub use num::Num;
|
||||
pub use shrinkwraprs::Shrinkwrap;
|
||||
pub use std::{
|
||||
cell::{Ref, RefCell},
|
||||
collections::{HashMap, HashSet},
|
||||
convert::{identity, TryFrom, TryInto},
|
||||
fmt::Display,
|
||||
hash::Hash,
|
||||
iter,
|
||||
iter::FromIterator,
|
||||
marker::PhantomData,
|
||||
ops::{Deref, DerefMut, Index, IndexMut},
|
||||
rc::{Rc, Weak},
|
||||
slice,
|
||||
slice::SliceIndex,
|
||||
};
|
||||
|
||||
pub trait Str = AsRef<str>;
|
||||
|
||||
pub fn default<T: Default>() -> T {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
#[derive(Derivative, Shrinkwrap)]
|
||||
#[shrinkwrap(mutable)]
|
||||
#[derivative(Clone(bound = "T: Clone"))]
|
||||
pub struct WithPhantomType<T, P = ()> {
|
||||
#[shrinkwrap(main_field)]
|
||||
pub t: T,
|
||||
phantom: PhantomData<P>,
|
||||
}
|
||||
|
||||
impl<T, P> WithPhantomType<T, P> {
|
||||
pub fn new(t: T) -> Self {
|
||||
let phantom = PhantomData;
|
||||
Self { t, phantom }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with<T, F: FnOnce(T) -> Out, Out>(t: T, f: F) -> Out {
|
||||
f(t)
|
||||
}
|
Loading…
Reference in New Issue
Block a user