Skip to content

Commit 41c149c

Browse files
committed
build: make lib no-std
Only when no runtime is used.
1 parent fbe24b0 commit 41c149c

12 files changed

Lines changed: 32 additions & 14 deletions

File tree

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[package]
22
name = "io-socket"
3-
description = "Set of I/O-free coroutines and runtimes to manage sockets"
3+
description = "I/O-free socket client library"
44
version = "0.0.1"
55
authors = ["Clément DOUIN <pimalaya.org@posteo.net>"]
66
rust-version = "1.87"
77
edition = "2024"
88
license = "MIT OR Apache-2.0"
9-
categories = ["api-bindings"]
10-
keywords = ["io-free", "coroutine", "socket", "stream", "datagram"]
9+
categories = ["api-bindings", "no-std"]
10+
keywords = ["io-free", "no-std", "coroutine", "socket", "stream"]
1111
homepage = "https://pimalaya.org"
1212
documentation = "https://docs.rs/io-socket/latest/io_socket"
1313
repository = "https://github.com/pimalaya/io-socket"

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# I/O Socket [![Documentation](https://img.shields.io/docsrs/io-socket?style=flat&logo=docs.rs&logoColor=white)](https://docs.rs/io-socket/latest/io_socket) [![Matrix](https://img.shields.io/badge/chat-%23pimalaya-blue?style=flat&logo=matrix&logoColor=white)](https://matrix.to/#/#pimalaya:matrix.org) [![Mastodon](https://img.shields.io/badge/news-%40pimalaya-blue?style=flat&logo=mastodon&logoColor=white)](https://fosstodon.org/@pimalaya)
22

3-
Set of **I/O-free** Rust coroutines and runtimes to manage sockets.
3+
**I/O-free** socket client library written in Rust
44

55
This library provides an I/O-agnostic abstraction over sockets — both stream sockets (TCP, Unix) and datagram sockets (UDP) — based on three concepts:
66

@@ -40,16 +40,16 @@ let mut read = ReadSocket::new();
4040
let (buf, n) = loop {
4141
match read.resume(arg.take()) {
4242
ReadSocketResult::Ok { buf, n } => break (buf, n),
43+
ReadSocketResult::Io { input } => arg = Some(handle(&mut stream, input).unwrap()),
4344
ReadSocketResult::Eof => break (vec![], 0),
4445
ReadSocketResult::Err { err } => panic!("{err}"),
45-
ReadSocketResult::Io { input } => arg = Some(handle(&mut stream, input).unwrap()),
4646
}
4747
};
4848
4949
let bytes = &buf[..n];
5050
```
5151

52-
### Write to a TCP stream (async Tokio)
52+
### Write on a TCP stream (async)
5353

5454
```rust,ignore
5555
use tokio::net::TcpStream;
@@ -67,9 +67,9 @@ let mut write = WriteSocket::new(b"GET / HTTP/1.0\r\n\r\n".to_vec());
6767
loop {
6868
match write.resume(arg.take()) {
6969
WriteSocketResult::Ok { .. } => break,
70+
WriteSocketResult::Io { input } => arg = Some(handle(&mut stream, input).await.unwrap()),
7071
WriteSocketResult::Eof => panic!("connection closed"),
7172
WriteSocketResult::Err { err } => panic!("{err}"),
72-
WriteSocketResult::Io { input } => arg = Some(handle(&mut stream, input).await.unwrap()),
7373
}
7474
}
7575
```
@@ -80,6 +80,7 @@ loop {
8080

8181
Have a look at projects built on the top of this library:
8282

83+
- [io-dns](https://github.com/pimalaya/io-dns): I/O-free DNS client library
8384
- [io-addressbook](https://github.com/pimalaya/io-addressbook): Set of I/O-free coroutines to manage contacts
8485
- [io-http](https://github.com/pimalaya/io-http): Set of I/O-free Rust coroutines to manage HTTP sockets
8586
- [io-oauth](https://github.com/pimalaya/io-oauth): Set of I/O-free Rust coroutines to manage OAuth flows

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
description = "Set of I/O-free Rust coroutines and runtimes to manage sockets";
2+
description = "I/O-free socket client library written in Rust";
33

44
inputs = {
55
nixpkgs = {

src/coroutines/read.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! I/O-free coroutine to read bytes into a buffer.
22
3-
use std::{fmt, mem};
3+
use alloc::{vec, vec::Vec};
4+
use core::{fmt, mem};
45

56
use log::{debug, trace};
67
use thiserror::Error;

src/coroutines/read_exact.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! I/O-free coroutine to read exactly N bytes from a socket.
22
3-
use std::mem;
3+
use alloc::vec::Vec;
4+
use core::mem;
45

56
use log::{debug, trace};
67
use thiserror::Error;

src/coroutines/read_to_end.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! I/O-free coroutine to read from a socket until EOF.
22
3-
use std::mem;
3+
use alloc::vec::Vec;
4+
use core::mem;
45

56
use log::trace;
67
use thiserror::Error;

src/coroutines/write.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! I/O-free coroutine to write bytes into a buffer.
22
3-
use std::{fmt, mem};
3+
use alloc::vec::Vec;
4+
use core::{fmt, mem};
45

56
use log::{debug, trace};
67
use thiserror::Error;

src/io.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Socket input and output.
22
3-
use std::fmt;
3+
use alloc::vec::Vec;
4+
use core::fmt;
45

56
/// Socket input emitted by [coroutines] and processed by [runtimes].
67
///

src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
22
#![doc = include_str!("../README.md")]
3+
#![no_std]
4+
extern crate alloc;
5+
// Runtime modules that wrap std or tokio bring std back explicitly.
6+
#[cfg(any(
7+
feature = "std-stream",
8+
feature = "std-udp-socket",
9+
feature = "tokio-stream"
10+
))]
11+
extern crate std;
312

413
pub mod coroutines;
514
pub mod io;

src/runtimes/std_stream.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
//! Synchronous stream socket runtime backed by [`io`].
1+
//! Synchronous stream socket runtime backed by [`std::io`].
22
3+
use alloc::vec::Vec;
34
use std::io::{Read, Result, Write};
45

56
use log::trace;

0 commit comments

Comments
 (0)