Skip to content

Commit

Permalink
Add no_std support and update README
Browse files Browse the repository at this point in the history
  • Loading branch information
matthunz committed Feb 18, 2024
1 parent 3ab0c84 commit 3a565b2
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 51 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ repository = "https://github.com/concoct-rs/concoct"
full = ["tracing"]

[dependencies]
futures = "0.3.30"
rustc-hash = "1.1.0"
futures = { version = "0.3.30", default-features = false }
hashbrown = { version = "0.14.3" }
tracing = { version = "0.1.40", optional = true }

[package.metadata.docs.rs]
Expand Down
46 changes: 11 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,26 @@
</a>
</div>

<div align="center">
<a href="https://github.com/concoct-rs/concoct/tree/main/web_examples">Examples</a>
</div>

<br />

Concoct is a framework for user-interfaces in Rust.

This crate provides a virtual DOM and state management system for any backend.
Concoct uses static typing to describe your UI at compile-time to create an efficient
tree without allocations.
Concoct is a reactive runtime for embedded systems.

```rust
use concoct::{Scope, View};
use concoct_web::html;

#[derive(Default)]
struct Counter {
count: i32,
}
use concoct::{
task::{self, Task},
System,
};

impl View<Self> for Counter {
fn body(&mut self, _cx: &Scope<Self>) -> impl View<Self> {
(
format!("High five count: {}", self.count),
html::button("Up high!").on_click(|_cx, state: &mut Self, _event| state.count += 1),
html::button("Down low!").on_click(|_cx, state: &mut Self, _event| state.count -= 1),
)
}
fn app(_count: &mut i32) -> impl Task<i32> {
task::from_fn(|_| dbg!("Hello World!"))
}

fn main() {
concoct_web::launch(Counter::default())
let mut system = System::new(0, app);
system.build();
system.rebuild();
}
```

## Installation
The easiest way to get started is using the `full` feature flag.

```
cargo add concoct --features full
```

To see a list of the available features flags that can be enabled, check our [docs](https://docs.rs/concoct/latest/concoct/#feature-flags).

## Inspiration
This crate is inspired by [xilem](https://github.com/linebender/xilem), React, and SwiftUI.
This crate is inspired by [xilem](https://github.com/linebender/xilem), [Drake](https://drake.mit.edu) and [ArduPilot](https://ardupilot.org).
16 changes: 10 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use std::{
#![no_std]

extern crate alloc;

use alloc::{collections::VecDeque, rc::Rc};
use core::{
cell::RefCell,
collections::{HashMap, VecDeque},
rc::Rc,
task::Waker,
task::{Poll, Waker},
};
use hashbrown::HashMap;
use task::{Scope, Task};

pub mod task;
Expand Down Expand Up @@ -75,10 +79,10 @@ impl<M: 'static, F, S> System<M, F, S> {
is_ready = true;
}
if is_ready {
std::task::Poll::Ready(())
Poll::Ready(())
} else {
queue.waker = Some(cx.waker().clone());
std::task::Poll::Pending
Poll::Pending
}
})
.await
Expand Down
3 changes: 2 additions & 1 deletion src/task/context.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::Task;
use std::{any::TypeId, marker::PhantomData, rc::Rc};
use alloc::rc::Rc;
use core::{any::TypeId, marker::PhantomData};

pub fn context<T: 'static>() -> Context<T> {
Context {
Expand Down
2 changes: 1 addition & 1 deletion src/task/from_fn.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::Task;
use std::marker::PhantomData;
use core::marker::PhantomData;

pub fn from_fn<F, M, O>(f: F) -> FromFn<F, M>
where
Expand Down
8 changes: 4 additions & 4 deletions src/task/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::any::{Any, TypeId};
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;
use alloc::rc::Rc;
use core::any::{Any, TypeId};
use core::cell::RefCell;
use hashbrown::HashMap;

mod context;
pub use self::context::{context, Context};
Expand Down
3 changes: 2 additions & 1 deletion src/task/provider.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::Task;
use std::{any::TypeId, rc::Rc};
use alloc::rc::Rc;
use core::any::TypeId;

pub fn provider<T: 'static>(value: T) -> Provider<T> {
Provider {
Expand Down
2 changes: 1 addition & 1 deletion src/task/then.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{Scope, Task};
use std::marker::PhantomData;
use core::marker::PhantomData;

pub struct Then<T1, F, T2, M> {
task: T1,
Expand Down

0 comments on commit 3a565b2

Please sign in to comment.