mirror of
https://github.com/fafhrd91/actix-net
synced 2025-08-18 08:05:32 +02:00
Compare commits
23 Commits
connect-v2
...
rt-1.1.0
Author | SHA1 | Date | |
---|---|---|---|
|
65e2e8052e | ||
|
783880bb0a | ||
|
69e8df9d62 | ||
|
9addf1a36b | ||
|
187a58472d | ||
|
30aa0b7bb6 | ||
|
e775d08d76 | ||
|
d5f95b54b7 | ||
|
904f90abc2 | ||
|
950c73077c | ||
|
732731a9c8 | ||
|
0dd5a7ce1d | ||
|
7105091e51 | ||
|
08959dfc21 | ||
|
2792433ad6 | ||
|
437a7b05c6 | ||
|
3d125c5381 | ||
|
fbf7d6ef33 | ||
|
e6b6f08369 | ||
|
4e806b3e3f | ||
|
f5b07053fc | ||
|
dd3bec83bf | ||
|
f955e49930 |
5
.github/workflows/linux.yml
vendored
5
.github/workflows/linux.yml
vendored
@@ -59,16 +59,15 @@ jobs:
|
|||||||
args: --all --all-features --no-fail-fast -- --nocapture
|
args: --all --all-features --no-fail-fast -- --nocapture
|
||||||
|
|
||||||
- name: Generate coverage file
|
- name: Generate coverage file
|
||||||
if: matrix.version == 'stable' && github.ref == 'refs/heads/master'
|
if: matrix.version == 'stable' && (github.ref == 'refs/heads/master' || github.event_name == 'pull_request')
|
||||||
run: |
|
run: |
|
||||||
cargo install cargo-tarpaulin
|
cargo install cargo-tarpaulin
|
||||||
cargo tarpaulin --out Xml --workspace --all-features
|
cargo tarpaulin --out Xml --workspace --all-features
|
||||||
|
|
||||||
- name: Upload to Codecov
|
- name: Upload to Codecov
|
||||||
if: matrix.version == 'stable' && github.ref == 'refs/heads/master'
|
if: matrix.version == 'stable' && (github.ref == 'refs/heads/master' || github.event_name == 'pull_request')
|
||||||
uses: codecov/codecov-action@v1
|
uses: codecov/codecov-action@v1
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.CODECOV_TOKEN }}
|
|
||||||
file: cobertura.xml
|
file: cobertura.xml
|
||||||
|
|
||||||
- name: Clear the cargo caches
|
- name: Clear the cargo caches
|
||||||
|
54
.github/workflows/windows-mingw.yml
vendored
Normal file
54
.github/workflows/windows-mingw.yml
vendored
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
name: CI (Windows-mingw)
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
env:
|
||||||
|
OPENSSL_DIR: d:\a\_temp\msys\msys64\usr
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build_and_test:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
version:
|
||||||
|
- stable
|
||||||
|
- nightly
|
||||||
|
|
||||||
|
name: ${{ matrix.version }} - x86_64-pc-windows-gnu
|
||||||
|
runs-on: windows-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@master
|
||||||
|
|
||||||
|
- name: Install ${{ matrix.version }}
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: ${{ matrix.version }}-x86_64-pc-windows-gnu
|
||||||
|
profile: minimal
|
||||||
|
override: true
|
||||||
|
|
||||||
|
- name: Install MSYS2
|
||||||
|
uses: numworks/setup-msys2@v1
|
||||||
|
|
||||||
|
- name: Install OpenSSL
|
||||||
|
run: |
|
||||||
|
msys2do pacman --noconfirm -S openssl-devel pkg-config
|
||||||
|
|
||||||
|
- name: Copy and check libs
|
||||||
|
run: |
|
||||||
|
Copy-Item d:\a\_temp\msys\msys64\usr\lib\libssl.dll.a d:\a\_temp\msys\msys64\usr\lib\libssl.dll
|
||||||
|
Copy-Item d:\a\_temp\msys\msys64\usr\lib\libcrypto.dll.a d:\a\_temp\msys\msys64\usr\lib\libcrypto.dll
|
||||||
|
Get-ChildItem d:\a\_temp\msys\msys64\usr\lib
|
||||||
|
Get-ChildItem d:\a\_temp\msys\msys64\usr
|
||||||
|
|
||||||
|
- name: check build
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: check
|
||||||
|
args: --all --bins --examples --tests
|
||||||
|
|
||||||
|
- name: tests
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: test
|
||||||
|
args: --all --all-features --no-fail-fast -- --nocapture
|
@@ -19,8 +19,8 @@ path = "src/lib.rs"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
bitflags = "1.2.1"
|
bitflags = "1.2.1"
|
||||||
bytes = "0.5.2"
|
bytes = "0.5.2"
|
||||||
futures-core = "0.3.1"
|
futures-core = { version = "0.3.4", default-features = false }
|
||||||
futures-sink = "0.3.1"
|
futures-sink = { version = "0.3.4", default-features = false }
|
||||||
tokio = { version = "0.2.4", default-features=false }
|
tokio = { version = "0.2.4", default-features=false }
|
||||||
tokio-util = { version = "0.2.0", default-features=false, features=["codec"] }
|
tokio-util = { version = "0.2.0", default-features=false, features=["codec"] }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
@@ -37,7 +37,7 @@ actix-utils = "1.0.6"
|
|||||||
actix-rt = "1.0.0"
|
actix-rt = "1.0.0"
|
||||||
derive_more = "0.99.2"
|
derive_more = "0.99.2"
|
||||||
either = "1.5.3"
|
either = "1.5.3"
|
||||||
futures = "0.3.1"
|
futures-util = { version = "0.3.4", default-features = false }
|
||||||
http = { version = "0.2.0", optional = true }
|
http = { version = "0.2.0", optional = true }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
trust-dns-proto = { version = "0.19", default-features = false, features = ["tokio-runtime"] }
|
trust-dns-proto = { version = "0.19", default-features = false, features = ["tokio-runtime"] }
|
||||||
|
@@ -8,7 +8,7 @@ use std::task::{Context, Poll};
|
|||||||
|
|
||||||
use actix_rt::net::TcpStream;
|
use actix_rt::net::TcpStream;
|
||||||
use actix_service::{Service, ServiceFactory};
|
use actix_service::{Service, ServiceFactory};
|
||||||
use futures::future::{err, ok, BoxFuture, Either, FutureExt, Ready};
|
use futures_util::future::{err, ok, BoxFuture, Either, FutureExt, Ready};
|
||||||
|
|
||||||
use super::connect::{Address, Connect, Connection};
|
use super::connect::{Address, Connect, Connection};
|
||||||
use super::error::ConnectError;
|
use super::error::ConnectError;
|
||||||
|
@@ -5,7 +5,7 @@ use std::pin::Pin;
|
|||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
use actix_service::{Service, ServiceFactory};
|
use actix_service::{Service, ServiceFactory};
|
||||||
use futures::future::{ok, Either, Ready};
|
use futures_util::future::{ok, Either, Ready};
|
||||||
use trust_dns_resolver::TokioAsyncResolver as AsyncResolver;
|
use trust_dns_resolver::TokioAsyncResolver as AsyncResolver;
|
||||||
use trust_dns_resolver::{error::ResolveError, lookup_ip::LookupIp};
|
use trust_dns_resolver::{error::ResolveError, lookup_ip::LookupIp};
|
||||||
|
|
||||||
|
@@ -5,7 +5,7 @@ use std::task::{Context, Poll};
|
|||||||
use actix_rt::net::TcpStream;
|
use actix_rt::net::TcpStream;
|
||||||
use actix_service::{Service, ServiceFactory};
|
use actix_service::{Service, ServiceFactory};
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use futures::future::{ok, Ready};
|
use futures_util::future::{ok, Ready};
|
||||||
use trust_dns_resolver::TokioAsyncResolver as AsyncResolver;
|
use trust_dns_resolver::TokioAsyncResolver as AsyncResolver;
|
||||||
|
|
||||||
use crate::connect::{Address, Connect, Connection};
|
use crate::connect::{Address, Connect, Connection};
|
||||||
|
@@ -10,7 +10,7 @@ pub use tokio_openssl::{HandshakeError, SslStream};
|
|||||||
use actix_codec::{AsyncRead, AsyncWrite};
|
use actix_codec::{AsyncRead, AsyncWrite};
|
||||||
use actix_rt::net::TcpStream;
|
use actix_rt::net::TcpStream;
|
||||||
use actix_service::{Service, ServiceFactory};
|
use actix_service::{Service, ServiceFactory};
|
||||||
use futures::future::{err, ok, Either, FutureExt, LocalBoxFuture, Ready};
|
use futures_util::future::{err, ok, Either, FutureExt, LocalBoxFuture, Ready};
|
||||||
use trust_dns_resolver::TokioAsyncResolver as AsyncResolver;
|
use trust_dns_resolver::TokioAsyncResolver as AsyncResolver;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -243,7 +243,7 @@ impl<T: Address> Future for OpensslConnectServiceResponse<T> {
|
|||||||
|
|
||||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
if let Some(ref mut fut) = self.fut1 {
|
if let Some(ref mut fut) = self.fut1 {
|
||||||
match futures::ready!(Pin::new(fut).poll(cx)) {
|
match futures_util::ready!(Pin::new(fut).poll(cx)) {
|
||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
let _ = self.fut1.take();
|
let _ = self.fut1.take();
|
||||||
self.fut2 = Some(self.openssl.call(res));
|
self.fut2 = Some(self.openssl.call(res));
|
||||||
@@ -253,7 +253,7 @@ impl<T: Address> Future for OpensslConnectServiceResponse<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ref mut fut) = self.fut2 {
|
if let Some(ref mut fut) = self.fut2 {
|
||||||
match futures::ready!(Pin::new(fut).poll(cx)) {
|
match futures_util::ready!(Pin::new(fut).poll(cx)) {
|
||||||
Ok(connect) => Poll::Ready(Ok(connect.into_parts().0)),
|
Ok(connect) => Poll::Ready(Ok(connect.into_parts().0)),
|
||||||
Err(e) => Poll::Ready(Err(ConnectError::Io(io::Error::new(
|
Err(e) => Poll::Ready(Err(ConnectError::Io(io::Error::new(
|
||||||
io::ErrorKind::Other,
|
io::ErrorKind::Other,
|
||||||
|
@@ -10,7 +10,7 @@ pub use tokio_rustls::{client::TlsStream, rustls::ClientConfig};
|
|||||||
|
|
||||||
use actix_codec::{AsyncRead, AsyncWrite};
|
use actix_codec::{AsyncRead, AsyncWrite};
|
||||||
use actix_service::{Service, ServiceFactory};
|
use actix_service::{Service, ServiceFactory};
|
||||||
use futures::future::{ok, Ready};
|
use futures_util::future::{ok, Ready};
|
||||||
use tokio_rustls::{Connect, TlsConnector};
|
use tokio_rustls::{Connect, TlsConnector};
|
||||||
use webpki::DNSNameRef;
|
use webpki::DNSNameRef;
|
||||||
|
|
||||||
@@ -126,7 +126,7 @@ where
|
|||||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
let this = self.get_mut();
|
let this = self.get_mut();
|
||||||
Poll::Ready(
|
Poll::Ready(
|
||||||
futures::ready!(Pin::new(&mut this.fut).poll(cx)).map(|stream| {
|
futures_util::ready!(Pin::new(&mut this.fut).poll(cx)).map(|stream| {
|
||||||
let s = this.stream.take().unwrap();
|
let s = this.stream.take().unwrap();
|
||||||
trace!("SSL Handshake success: {:?}", s.host());
|
trace!("SSL Handshake success: {:?}", s.host());
|
||||||
s.replace(stream).1
|
s.replace(stream).1
|
||||||
|
@@ -5,7 +5,7 @@ use actix_rt::net::TcpStream;
|
|||||||
use actix_service::{fn_service, Service, ServiceFactory};
|
use actix_service::{fn_service, Service, ServiceFactory};
|
||||||
use actix_testing::TestServer;
|
use actix_testing::TestServer;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures::SinkExt;
|
use futures_util::sink::SinkExt;
|
||||||
|
|
||||||
use actix_connect::resolver::{ResolverConfig, ResolverOpts};
|
use actix_connect::resolver::{ResolverConfig, ResolverOpts};
|
||||||
use actix_connect::Connect;
|
use actix_connect::Connect;
|
||||||
|
@@ -22,10 +22,12 @@ actix-utils = "1.0.4"
|
|||||||
actix-rt = "1.0.0"
|
actix-rt = "1.0.0"
|
||||||
bytes = "0.5.3"
|
bytes = "0.5.3"
|
||||||
either = "1.5.3"
|
either = "1.5.3"
|
||||||
futures = "0.3.1"
|
futures-sink = { version = "0.3.4", default-features = false }
|
||||||
|
futures-core = { version = "0.3.4", default-features = false }
|
||||||
pin-project = "0.4.6"
|
pin-project = "0.4.6"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
actix-connect = "2.0.0-alpha.2"
|
actix-connect = "2.0.0-alpha.2"
|
||||||
actix-testing = "1.0.0"
|
actix-testing = "1.0.0"
|
||||||
|
futures-util = { version = "0.3.4", default-features = false }
|
||||||
|
@@ -4,7 +4,7 @@ use std::task::{Context, Poll};
|
|||||||
|
|
||||||
use actix_codec::{AsyncRead, AsyncWrite, Decoder, Encoder, Framed};
|
use actix_codec::{AsyncRead, AsyncWrite, Decoder, Encoder, Framed};
|
||||||
use actix_utils::mpsc::Receiver;
|
use actix_utils::mpsc::Receiver;
|
||||||
use futures::Stream;
|
use futures_core::stream::Stream;
|
||||||
|
|
||||||
pub struct Connect<Io, Codec>
|
pub struct Connect<Io, Codec>
|
||||||
where
|
where
|
||||||
@@ -90,7 +90,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Io, St, Codec, Out> futures::Sink<<Codec as Encoder>::Item>
|
impl<Io, St, Codec, Out> futures_sink::Sink<<Codec as Encoder>::Item>
|
||||||
for ConnectResult<Io, St, Codec, Out>
|
for ConnectResult<Io, St, Codec, Out>
|
||||||
where
|
where
|
||||||
Io: AsyncRead + AsyncWrite,
|
Io: AsyncRead + AsyncWrite,
|
||||||
|
@@ -5,7 +5,7 @@ use std::task::{Context, Poll};
|
|||||||
use actix_codec::{AsyncRead, AsyncWrite, Decoder, Encoder, Framed};
|
use actix_codec::{AsyncRead, AsyncWrite, Decoder, Encoder, Framed};
|
||||||
use actix_service::Service;
|
use actix_service::Service;
|
||||||
use actix_utils::mpsc;
|
use actix_utils::mpsc;
|
||||||
use futures::Stream;
|
use futures_core::stream::Stream;
|
||||||
use pin_project::pin_project;
|
use pin_project::pin_project;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
|
||||||
|
@@ -7,7 +7,7 @@ use std::task::{Context, Poll};
|
|||||||
use actix_codec::{AsyncRead, AsyncWrite, Decoder, Encoder, Framed};
|
use actix_codec::{AsyncRead, AsyncWrite, Decoder, Encoder, Framed};
|
||||||
use actix_service::{IntoService, IntoServiceFactory, Service, ServiceFactory};
|
use actix_service::{IntoService, IntoServiceFactory, Service, ServiceFactory};
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use futures::{ready, Stream};
|
use futures_core::{ready, stream::Stream};
|
||||||
use pin_project::project;
|
use pin_project::project;
|
||||||
|
|
||||||
use crate::connect::{Connect, ConnectResult};
|
use crate::connect::{Connect, ConnectResult};
|
||||||
|
@@ -6,7 +6,7 @@ use actix_service::{fn_factory_with_config, fn_service, IntoService, Service};
|
|||||||
use actix_testing::TestServer;
|
use actix_testing::TestServer;
|
||||||
use actix_utils::mpsc;
|
use actix_utils::mpsc;
|
||||||
use bytes::{Bytes, BytesMut};
|
use bytes::{Bytes, BytesMut};
|
||||||
use futures::future::ok;
|
use futures_util::future::ok;
|
||||||
|
|
||||||
use actix_ioframe::{Builder, Connect, FactoryBuilder};
|
use actix_ioframe::{Builder, Connect, FactoryBuilder};
|
||||||
|
|
||||||
|
@@ -1,10 +1,17 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## [TBD] - [TBD]
|
## [1.1.0] - 2020-04-08
|
||||||
|
|
||||||
- Expose `System::is_set` to check if current system is running
|
### Added
|
||||||
|
|
||||||
- Add `Arbiter::local_join` associated function to get be able to `await` for spawned futures
|
* Expose `System::is_set` to check if current system has ben started [#99]
|
||||||
|
* Add `Arbiter::is_running` to check if event loop is running [#124]
|
||||||
|
* Add `Arbiter::local_join` associated function
|
||||||
|
to get be able to `await` for spawned futures [#94]
|
||||||
|
|
||||||
|
[#94]: https://github.com/actix/actix-net/pull/94
|
||||||
|
[#99]: https://github.com/actix/actix-net/pull/99
|
||||||
|
[#124]: https://github.com/actix/actix-net/pull/124
|
||||||
|
|
||||||
## [1.0.0] - 2019-12-11
|
## [1.0.0] - 2019-12-11
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-rt"
|
name = "actix-rt"
|
||||||
version = "1.0.0"
|
version = "1.1.0"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Actix runtime"
|
description = "Actix runtime"
|
||||||
keywords = ["network", "framework", "async", "futures"]
|
keywords = ["network", "framework", "async", "futures"]
|
||||||
@@ -18,7 +18,7 @@ path = "src/lib.rs"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
actix-macros = "0.1.0"
|
actix-macros = "0.1.0"
|
||||||
actix-threadpool = "0.3"
|
actix-threadpool = "0.3"
|
||||||
futures-channel = { version = "0.3.1", default-features = false }
|
futures-channel = { version = "0.3.4", default-features = false }
|
||||||
futures-util = { version = "0.3.1", default-features = false }
|
futures-util = { version = "0.3.4", default-features = false, features = ["alloc"] }
|
||||||
copyless = "0.1.4"
|
copyless = "0.1.4"
|
||||||
tokio = { version = "0.2.6", default-features = false, features = ["rt-core", "rt-util", "io-driver", "tcp", "uds", "udp", "time", "signal", "stream"] }
|
tokio = { version = "0.2.6", default-features = false, features = ["rt-core", "rt-util", "io-driver", "tcp", "uds", "udp", "time", "signal", "stream"] }
|
||||||
|
@@ -8,7 +8,10 @@ use std::{fmt, thread};
|
|||||||
|
|
||||||
use futures_channel::mpsc::{unbounded, UnboundedReceiver, UnboundedSender};
|
use futures_channel::mpsc::{unbounded, UnboundedReceiver, UnboundedSender};
|
||||||
use futures_channel::oneshot::{channel, Canceled, Sender};
|
use futures_channel::oneshot::{channel, Canceled, Sender};
|
||||||
use futures_util::{future::{self, Future, FutureExt}, stream::Stream};
|
use futures_util::{
|
||||||
|
future::{self, Future, FutureExt},
|
||||||
|
stream::Stream,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::runtime::Runtime;
|
use crate::runtime::Runtime;
|
||||||
use crate::system::System;
|
use crate::system::System;
|
||||||
@@ -86,6 +89,11 @@ impl Arbiter {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check if current arbiter is running.
|
||||||
|
pub fn is_running() -> bool {
|
||||||
|
RUNNING.with(|cell| cell.get())
|
||||||
|
}
|
||||||
|
|
||||||
/// Stop arbiter from continuing it's event loop.
|
/// Stop arbiter from continuing it's event loop.
|
||||||
pub fn stop(&self) {
|
pub fn stop(&self) {
|
||||||
let _ = self.sender.unbounded_send(ArbiterCommand::Stop);
|
let _ = self.sender.unbounded_send(ArbiterCommand::Stop);
|
||||||
@@ -180,8 +188,7 @@ impl Arbiter {
|
|||||||
// Box the future and push it to the queue, this results in double boxing
|
// Box the future and push it to the queue, this results in double boxing
|
||||||
// because the executor boxes the future again, but works for now
|
// because the executor boxes the future again, but works for now
|
||||||
Q.with(move |cell| {
|
Q.with(move |cell| {
|
||||||
cell.borrow_mut()
|
cell.borrow_mut().push(Pin::from(Box::alloc().init(future)))
|
||||||
.push(Pin::from(Box::alloc().init(future)))
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -79,7 +79,7 @@ impl System {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if current system is running.
|
/// Check if current system is set, i.e., as already been started.
|
||||||
pub fn is_set() -> bool {
|
pub fn is_set() -> bool {
|
||||||
CURRENT.with(|cell| cell.borrow().is_some())
|
CURRENT.with(|cell| cell.borrow().is_some())
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,19 @@
|
|||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn start_and_stop() {
|
||||||
|
actix_rt::System::new("start_and_stop").block_on(async move {
|
||||||
|
assert!(
|
||||||
|
actix_rt::Arbiter::is_running(),
|
||||||
|
"System doesn't seem to have started"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
assert!(
|
||||||
|
!actix_rt::Arbiter::is_running(),
|
||||||
|
"System doesn't seem to have stopped"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn await_for_timer() {
|
fn await_for_timer() {
|
||||||
let time = Duration::from_secs(2);
|
let time = Duration::from_secs(2);
|
@@ -30,7 +30,8 @@ log = "0.4"
|
|||||||
num_cpus = "1.11"
|
num_cpus = "1.11"
|
||||||
mio = "0.6.19"
|
mio = "0.6.19"
|
||||||
net2 = "0.2"
|
net2 = "0.2"
|
||||||
futures = "0.3.1"
|
futures-channel = { version = "0.3.4", default-features = false }
|
||||||
|
futures-util = { version = "0.3.4", default-features = false, features = ["sink"] }
|
||||||
slab = "0.4"
|
slab = "0.4"
|
||||||
|
|
||||||
# unix domain sockets
|
# unix domain sockets
|
||||||
|
@@ -6,11 +6,11 @@ use std::{io, mem, net};
|
|||||||
use actix_rt::net::TcpStream;
|
use actix_rt::net::TcpStream;
|
||||||
use actix_rt::time::{delay_until, Instant};
|
use actix_rt::time::{delay_until, Instant};
|
||||||
use actix_rt::{spawn, System};
|
use actix_rt::{spawn, System};
|
||||||
use futures::channel::mpsc::{unbounded, UnboundedReceiver};
|
use futures_channel::mpsc::{unbounded, UnboundedReceiver};
|
||||||
use futures::channel::oneshot;
|
use futures_channel::oneshot;
|
||||||
use futures::future::ready;
|
use futures_util::future::ready;
|
||||||
use futures::stream::FuturesUnordered;
|
use futures_util::stream::FuturesUnordered;
|
||||||
use futures::{ready, Future, FutureExt, Stream, StreamExt};
|
use futures_util::{ready, future::Future, FutureExt, stream::Stream, StreamExt};
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use net2::TcpBuilder;
|
use net2::TcpBuilder;
|
||||||
|
|
||||||
|
@@ -4,7 +4,7 @@ use std::{fmt, io, net};
|
|||||||
use actix_rt::net::TcpStream;
|
use actix_rt::net::TcpStream;
|
||||||
use actix_service as actix;
|
use actix_service as actix;
|
||||||
use actix_utils::counter::CounterGuard;
|
use actix_utils::counter::CounterGuard;
|
||||||
use futures::future::{ok, Future, FutureExt, LocalBoxFuture};
|
use futures_util::future::{ok, Future, FutureExt, LocalBoxFuture};
|
||||||
use log::error;
|
use log::error;
|
||||||
|
|
||||||
use super::builder::bind_addr;
|
use super::builder::bind_addr;
|
||||||
|
@@ -3,9 +3,9 @@ use std::io;
|
|||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
use futures::channel::mpsc::UnboundedSender;
|
use futures_channel::mpsc::UnboundedSender;
|
||||||
use futures::channel::oneshot;
|
use futures_channel::oneshot;
|
||||||
use futures::FutureExt;
|
use futures_util::FutureExt;
|
||||||
|
|
||||||
use crate::builder::ServerBuilder;
|
use crate::builder::ServerBuilder;
|
||||||
use crate::signals::Signal;
|
use crate::signals::Signal;
|
||||||
|
@@ -6,8 +6,8 @@ use std::time::Duration;
|
|||||||
use actix_rt::spawn;
|
use actix_rt::spawn;
|
||||||
use actix_service::{self as actix, Service, ServiceFactory as ActixServiceFactory};
|
use actix_service::{self as actix, Service, ServiceFactory as ActixServiceFactory};
|
||||||
use actix_utils::counter::CounterGuard;
|
use actix_utils::counter::CounterGuard;
|
||||||
use futures::future::{err, ok, LocalBoxFuture, Ready};
|
use futures_util::future::{err, ok, LocalBoxFuture, Ready};
|
||||||
use futures::{FutureExt, TryFutureExt};
|
use futures_util::{FutureExt, TryFutureExt};
|
||||||
use log::error;
|
use log::error;
|
||||||
|
|
||||||
use super::Token;
|
use super::Token;
|
||||||
|
@@ -3,7 +3,7 @@ use std::io;
|
|||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
use futures::future::lazy;
|
use futures_util::future::lazy;
|
||||||
|
|
||||||
use crate::server::Server;
|
use crate::server::Server;
|
||||||
|
|
||||||
|
@@ -7,10 +7,10 @@ use std::time;
|
|||||||
use actix_rt::time::{delay_until, Delay, Instant};
|
use actix_rt::time::{delay_until, Delay, Instant};
|
||||||
use actix_rt::{spawn, Arbiter};
|
use actix_rt::{spawn, Arbiter};
|
||||||
use actix_utils::counter::Counter;
|
use actix_utils::counter::Counter;
|
||||||
use futures::channel::mpsc::{unbounded, UnboundedReceiver, UnboundedSender};
|
use futures_channel::mpsc::{unbounded, UnboundedReceiver, UnboundedSender};
|
||||||
use futures::channel::oneshot;
|
use futures_channel::oneshot;
|
||||||
use futures::future::{join_all, LocalBoxFuture, MapOk};
|
use futures_util::future::{join_all, LocalBoxFuture, MapOk};
|
||||||
use futures::{Future, FutureExt, Stream, TryFutureExt};
|
use futures_util::{future::Future, FutureExt, stream::Stream, TryFutureExt};
|
||||||
use log::{error, info, trace};
|
use log::{error, info, trace};
|
||||||
|
|
||||||
use crate::accept::AcceptNotify;
|
use crate::accept::AcceptNotify;
|
||||||
|
@@ -4,7 +4,7 @@ use std::{net, thread, time};
|
|||||||
|
|
||||||
use actix_server::Server;
|
use actix_server::Server;
|
||||||
use actix_service::fn_service;
|
use actix_service::fn_service;
|
||||||
use futures::future::{lazy, ok};
|
use futures_util::future::{lazy, ok};
|
||||||
use net2::TcpBuilder;
|
use net2::TcpBuilder;
|
||||||
|
|
||||||
fn unused_addr() -> net::SocketAddr {
|
fn unused_addr() -> net::SocketAddr {
|
||||||
@@ -71,7 +71,7 @@ fn test_start() {
|
|||||||
use actix_codec::{BytesCodec, Framed};
|
use actix_codec::{BytesCodec, Framed};
|
||||||
use actix_rt::net::TcpStream;
|
use actix_rt::net::TcpStream;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures::SinkExt;
|
use futures_util::sink::SinkExt;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
|
||||||
let addr = unused_addr();
|
let addr = unused_addr();
|
||||||
|
@@ -24,4 +24,3 @@ actix-service = "1.0.0"
|
|||||||
|
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
net2 = "0.2"
|
net2 = "0.2"
|
||||||
futures = "0.3.1"
|
|
||||||
|
@@ -48,6 +48,8 @@ pub enum BlockingError<E: fmt::Debug> {
|
|||||||
Canceled,
|
Canceled,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<E: fmt::Debug> std::error::Error for BlockingError<E> {}
|
||||||
|
|
||||||
/// Execute blocking function on a thread pool, returns future that resolves
|
/// Execute blocking function on a thread pool, returns future that resolves
|
||||||
/// to result of the function execution.
|
/// to result of the function execution.
|
||||||
pub fn run<F, I, E>(f: F) -> CpuFuture<I, E>
|
pub fn run<F, I, E>(f: F) -> CpuFuture<I, E>
|
||||||
|
@@ -38,7 +38,7 @@ actix-utils = "1.0.0"
|
|||||||
actix-rt = "1.0.0"
|
actix-rt = "1.0.0"
|
||||||
derive_more = "0.99.2"
|
derive_more = "0.99.2"
|
||||||
either = "1.5.2"
|
either = "1.5.2"
|
||||||
futures = "0.3.1"
|
futures-util = { version = "0.3.4", default-features = false }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
||||||
# openssl
|
# openssl
|
||||||
|
@@ -4,7 +4,7 @@ use std::task::{Context, Poll};
|
|||||||
use actix_codec::{AsyncRead, AsyncWrite};
|
use actix_codec::{AsyncRead, AsyncWrite};
|
||||||
use actix_service::{Service, ServiceFactory};
|
use actix_service::{Service, ServiceFactory};
|
||||||
use actix_utils::counter::Counter;
|
use actix_utils::counter::Counter;
|
||||||
use futures::future::{self, FutureExt, LocalBoxFuture, TryFutureExt};
|
use futures_util::future::{self, FutureExt, LocalBoxFuture, TryFutureExt};
|
||||||
pub use native_tls::Error;
|
pub use native_tls::Error;
|
||||||
pub use tokio_tls::{TlsAcceptor, TlsStream};
|
pub use tokio_tls::{TlsAcceptor, TlsStream};
|
||||||
|
|
||||||
|
@@ -9,7 +9,7 @@ pub use tokio_openssl::{HandshakeError, SslStream};
|
|||||||
use actix_codec::{AsyncRead, AsyncWrite};
|
use actix_codec::{AsyncRead, AsyncWrite};
|
||||||
use actix_service::{Service, ServiceFactory};
|
use actix_service::{Service, ServiceFactory};
|
||||||
use actix_utils::counter::{Counter, CounterGuard};
|
use actix_utils::counter::{Counter, CounterGuard};
|
||||||
use futures::future::{ok, FutureExt, LocalBoxFuture, Ready};
|
use futures_util::future::{ok, FutureExt, LocalBoxFuture, Ready};
|
||||||
|
|
||||||
use crate::MAX_CONN_COUNTER;
|
use crate::MAX_CONN_COUNTER;
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ impl<T: AsyncRead + AsyncWrite + Unpin> Future for AcceptorServiceResponse<T> {
|
|||||||
type Output = Result<SslStream<T>, HandshakeError<T>>;
|
type Output = Result<SslStream<T>, HandshakeError<T>>;
|
||||||
|
|
||||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
let io = futures::ready!(Pin::new(&mut self.fut).poll(cx))?;
|
let io = futures_util::ready!(Pin::new(&mut self.fut).poll(cx))?;
|
||||||
Poll::Ready(Ok(io))
|
Poll::Ready(Ok(io))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,7 +8,7 @@ use std::task::{Context, Poll};
|
|||||||
use actix_codec::{AsyncRead, AsyncWrite};
|
use actix_codec::{AsyncRead, AsyncWrite};
|
||||||
use actix_service::{Service, ServiceFactory};
|
use actix_service::{Service, ServiceFactory};
|
||||||
use actix_utils::counter::{Counter, CounterGuard};
|
use actix_utils::counter::{Counter, CounterGuard};
|
||||||
use futures::future::{ok, Ready};
|
use futures_util::future::{ok, Ready};
|
||||||
use tokio_rustls::{Accept, TlsAcceptor};
|
use tokio_rustls::{Accept, TlsAcceptor};
|
||||||
|
|
||||||
pub use rust_tls::{ServerConfig, Session};
|
pub use rust_tls::{ServerConfig, Session};
|
||||||
@@ -108,7 +108,7 @@ impl<T: AsyncRead + AsyncWrite + Unpin> Future for AcceptorServiceFut<T> {
|
|||||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
let this = self.get_mut();
|
let this = self.get_mut();
|
||||||
|
|
||||||
let res = futures::ready!(Pin::new(&mut this.fut).poll(cx));
|
let res = futures_util::ready!(Pin::new(&mut this.fut).poll(cx));
|
||||||
match res {
|
match res {
|
||||||
Ok(io) => Poll::Ready(Ok(io)),
|
Ok(io) => Poll::Ready(Ok(io)),
|
||||||
Err(e) => Poll::Ready(Err(e)),
|
Err(e) => Poll::Ready(Err(e)),
|
||||||
|
@@ -17,7 +17,7 @@ path = "src/lib.rs"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-service = "1.0.4"
|
actix-service = "1.0.4"
|
||||||
futures-util = "0.3.1"
|
futures-util = { version = "0.3.4", default-features = false }
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-futures = "0.2"
|
tracing-futures = "0.2"
|
||||||
|
|
||||||
|
@@ -22,7 +22,9 @@ actix-codec = "0.2.0"
|
|||||||
bitflags = "1.2"
|
bitflags = "1.2"
|
||||||
bytes = "0.5.3"
|
bytes = "0.5.3"
|
||||||
either = "1.5.3"
|
either = "1.5.3"
|
||||||
futures = "0.3.1"
|
futures-channel = { version = "0.3.4", default-features = false }
|
||||||
|
futures-sink = { version = "0.3.4", default-features = false }
|
||||||
|
futures-util = { version = "0.3.4", default-features = false }
|
||||||
pin-project = "0.4.6"
|
pin-project = "0.4.6"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
slab = "0.4"
|
slab = "0.4"
|
||||||
|
@@ -96,7 +96,7 @@ impl Drop for Waiter {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use futures::future::lazy;
|
use futures_util::future::lazy;
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_condition() {
|
async fn test_condition() {
|
||||||
|
@@ -3,7 +3,7 @@ use std::pin::Pin;
|
|||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
use actix_service::{Service, ServiceFactory};
|
use actix_service::{Service, ServiceFactory};
|
||||||
use futures::{future, ready, Future};
|
use futures_util::{future, ready, future::Future};
|
||||||
|
|
||||||
/// Combine two different service types into a single type.
|
/// Combine two different service types into a single type.
|
||||||
///
|
///
|
||||||
|
@@ -6,7 +6,7 @@ use std::{fmt, mem};
|
|||||||
|
|
||||||
use actix_codec::{AsyncRead, AsyncWrite, Decoder, Encoder, Framed};
|
use actix_codec::{AsyncRead, AsyncWrite, Decoder, Encoder, Framed};
|
||||||
use actix_service::{IntoService, Service};
|
use actix_service::{IntoService, Service};
|
||||||
use futures::{Future, FutureExt, Stream};
|
use futures_util::{future::Future, FutureExt, stream::Stream};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
|
||||||
use crate::mpsc;
|
use crate::mpsc;
|
||||||
|
@@ -4,7 +4,7 @@ use std::pin::Pin;
|
|||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
use actix_service::{IntoService, Service, Transform};
|
use actix_service::{IntoService, Service, Transform};
|
||||||
use futures::future::{ok, Ready};
|
use futures_util::future::{ok, Ready};
|
||||||
|
|
||||||
use super::counter::{Counter, CounterGuard};
|
use super::counter::{Counter, CounterGuard};
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ mod tests {
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use actix_service::{apply, fn_factory, Service, ServiceFactory};
|
use actix_service::{apply, fn_factory, Service, ServiceFactory};
|
||||||
use futures::future::{lazy, ok, FutureExt, LocalBoxFuture};
|
use futures_util::future::{lazy, ok, FutureExt, LocalBoxFuture};
|
||||||
|
|
||||||
struct SleepService(Duration);
|
struct SleepService(Duration);
|
||||||
|
|
||||||
|
@@ -7,7 +7,7 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use actix_rt::time::{delay_until, Delay, Instant};
|
use actix_rt::time::{delay_until, Delay, Instant};
|
||||||
use actix_service::{Service, ServiceFactory};
|
use actix_service::{Service, ServiceFactory};
|
||||||
use futures::future::{ok, Ready};
|
use futures_util::future::{ok, Ready};
|
||||||
|
|
||||||
use super::time::{LowResTime, LowResTimeService};
|
use super::time::{LowResTime, LowResTimeService};
|
||||||
|
|
||||||
|
@@ -6,7 +6,8 @@ use std::fmt;
|
|||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
use futures::{Sink, Stream};
|
use futures_sink::Sink;
|
||||||
|
use futures_util::stream::Stream;
|
||||||
|
|
||||||
use crate::cell::Cell;
|
use crate::cell::Cell;
|
||||||
use crate::task::LocalWaker;
|
use crate::task::LocalWaker;
|
||||||
@@ -180,8 +181,8 @@ impl<T> SendError<T> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use futures::future::lazy;
|
use futures_util::future::lazy;
|
||||||
use futures::{Stream, StreamExt};
|
use futures_util::{stream::Stream, StreamExt};
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_mpsc() {
|
async fn test_mpsc() {
|
||||||
|
@@ -3,7 +3,7 @@ use std::future::Future;
|
|||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
pub use futures::channel::oneshot::Canceled;
|
pub use futures_channel::oneshot::Canceled;
|
||||||
use slab::Slab;
|
use slab::Slab;
|
||||||
|
|
||||||
use crate::cell::Cell;
|
use crate::cell::Cell;
|
||||||
@@ -253,7 +253,7 @@ impl<T> Future for PReceiver<T> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use futures::future::lazy;
|
use futures_util::future::lazy;
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_oneshot() {
|
async fn test_oneshot() {
|
||||||
|
@@ -8,7 +8,7 @@ use std::rc::Rc;
|
|||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
use actix_service::{IntoService, Service, Transform};
|
use actix_service::{IntoService, Service, Transform};
|
||||||
use futures::future::{ok, Ready};
|
use futures_util::future::{ok, Ready};
|
||||||
|
|
||||||
use crate::oneshot;
|
use crate::oneshot;
|
||||||
use crate::task::LocalWaker;
|
use crate::task::LocalWaker;
|
||||||
@@ -210,8 +210,8 @@ mod tests {
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use actix_service::Service;
|
use actix_service::Service;
|
||||||
use futures::channel::oneshot;
|
use futures_channel::oneshot;
|
||||||
use futures::future::{lazy, poll_fn, FutureExt, LocalBoxFuture};
|
use futures_util::future::{lazy, poll_fn, FutureExt, LocalBoxFuture};
|
||||||
|
|
||||||
struct Srv;
|
struct Srv;
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@ use std::pin::Pin;
|
|||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
use actix_service::{IntoService, Service};
|
use actix_service::{IntoService, Service};
|
||||||
use futures::{FutureExt, Stream};
|
use futures_util::{FutureExt, stream::Stream};
|
||||||
|
|
||||||
use crate::mpsc;
|
use crate::mpsc;
|
||||||
|
|
||||||
|
@@ -4,7 +4,7 @@ use std::time::{self, Duration, Instant};
|
|||||||
|
|
||||||
use actix_rt::time::delay_for;
|
use actix_rt::time::delay_for;
|
||||||
use actix_service::{Service, ServiceFactory};
|
use actix_service::{Service, ServiceFactory};
|
||||||
use futures::future::{ok, ready, FutureExt, Ready};
|
use futures_util::future::{ok, ready, FutureExt, Ready};
|
||||||
|
|
||||||
use super::cell::Cell;
|
use super::cell::Cell;
|
||||||
|
|
||||||
|
@@ -10,7 +10,7 @@ use std::{fmt, time};
|
|||||||
|
|
||||||
use actix_rt::time::{delay_for, Delay};
|
use actix_rt::time::{delay_for, Delay};
|
||||||
use actix_service::{IntoService, Service, Transform};
|
use actix_service::{IntoService, Service, Transform};
|
||||||
use futures::future::{ok, Ready};
|
use futures_util::future::{ok, Ready};
|
||||||
|
|
||||||
/// Applies a timeout to requests.
|
/// Applies a timeout to requests.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -183,7 +183,7 @@ mod tests {
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use actix_service::{apply, fn_factory, Service, ServiceFactory};
|
use actix_service::{apply, fn_factory, Service, ServiceFactory};
|
||||||
use futures::future::{ok, FutureExt, LocalBoxFuture};
|
use futures_util::future::{ok, FutureExt, LocalBoxFuture};
|
||||||
|
|
||||||
struct SleepService(Duration);
|
struct SleepService(Duration);
|
||||||
|
|
||||||
|
@@ -11,7 +11,7 @@ use actix_codec::{AsyncRead, AsyncWrite};
|
|||||||
use actix_rt::System;
|
use actix_rt::System;
|
||||||
use actix_server::{Io, Server};
|
use actix_server::{Io, Server};
|
||||||
use actix_service::{service_fn, NewService};
|
use actix_service::{service_fn, NewService};
|
||||||
use futures::{future, Future};
|
use futures_util::{future, Future};
|
||||||
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
|
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
|
||||||
use tokio_openssl::SslAcceptorExt;
|
use tokio_openssl::SslAcceptorExt;
|
||||||
|
|
||||||
|
@@ -7,7 +7,7 @@ use std::sync::{
|
|||||||
use actix_rt::System;
|
use actix_rt::System;
|
||||||
use actix_server::{ssl, Server};
|
use actix_server::{ssl, Server};
|
||||||
use actix_service::NewService;
|
use actix_service::NewService;
|
||||||
use futures::future;
|
use futures_util::future;
|
||||||
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
|
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@@ -31,7 +31,7 @@ fn set_bit(array: &mut [u8], ch: u8) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
thread_local! {
|
thread_local! {
|
||||||
static DEFAULT_QUOTER: Quoter = { Quoter::new(b"@:", b"/+") };
|
static DEFAULT_QUOTER: Quoter = Quoter::new(b"@:", b"/+");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Clone, Debug)]
|
#[derive(Default, Clone, Debug)]
|
||||||
|
@@ -1,5 +1,9 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.1.5] - 2020-03-30
|
||||||
|
|
||||||
|
* Serde support
|
||||||
|
|
||||||
## [0.1.4] - 2020-01-14
|
## [0.1.4] - 2020-01-14
|
||||||
|
|
||||||
* Fix `AsRef<str>` impl
|
* Fix `AsRef<str>` impl
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "bytestring"
|
name = "bytestring"
|
||||||
version = "0.1.4"
|
version = "0.1.5"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "A UTF-8 encoded string with Bytes as a storage"
|
description = "A UTF-8 encoded string with Bytes as a storage"
|
||||||
keywords = ["actix"]
|
keywords = ["actix"]
|
||||||
@@ -16,3 +16,7 @@ path = "src/lib.rs"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bytes = "0.5.3"
|
bytes = "0.5.3"
|
||||||
|
serde = { version = "1.0", optional = true }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
serde_json = "1.0"
|
@@ -159,6 +159,34 @@ impl fmt::Display for ByteString {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
mod serde {
|
||||||
|
use serde::de::{Deserialize, Deserializer};
|
||||||
|
use serde::ser::{Serialize, Serializer};
|
||||||
|
|
||||||
|
use super::ByteString;
|
||||||
|
|
||||||
|
impl Serialize for ByteString {
|
||||||
|
#[inline]
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
serializer.serialize_str(self.as_ref())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'de> Deserialize<'de> for ByteString {
|
||||||
|
#[inline]
|
||||||
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
String::deserialize(deserializer).map(ByteString::from)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -222,4 +250,18 @@ mod test {
|
|||||||
fn test_try_from_bytesmut() {
|
fn test_try_from_bytesmut() {
|
||||||
let _ = ByteString::try_from(bytes::BytesMut::from(&b"nice bytes"[..])).unwrap();
|
let _ = ByteString::try_from(bytes::BytesMut::from(&b"nice bytes"[..])).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
#[test]
|
||||||
|
fn test_serialize() {
|
||||||
|
let s: ByteString = serde_json::from_str(r#""nice bytes""#).unwrap();
|
||||||
|
assert_eq!(s, "nice bytes");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
#[test]
|
||||||
|
fn test_deserialize() {
|
||||||
|
let s = serde_json::to_string(&ByteString::from_static("nice bytes")).unwrap();
|
||||||
|
assert_eq!(s, r#""nice bytes""#);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user