rw_deno_core/io/
mod.rs

1// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2
3// Think of Resources as File Descriptors. They are integers that are allocated
4// by the privileged side of Deno which refer to various rust objects that need
5// to be persisted between various ops. For example, network sockets are
6// resources. Resources may or may not correspond to a real operating system
7// file descriptor (hence the different name).
8
9use anyhow::Error;
10use futures::Future;
11use std::pin::Pin;
12
13mod buffer_strategy;
14mod buffers;
15mod resource;
16mod resource_handle;
17mod resource_table;
18
19pub use buffer_strategy::AdaptiveBufferStrategy;
20pub use buffers::BufMutView;
21pub use buffers::BufMutViewWhole;
22pub use buffers::BufView;
23pub use resource::Resource;
24pub use resource_handle::ResourceHandle;
25pub use resource_handle::ResourceHandleFd;
26pub use resource_handle::ResourceHandleSocket;
27pub use resource_table::ResourceId;
28pub use resource_table::ResourceTable;
29
30/// Returned by resource shutdown methods
31pub type AsyncResult<T> = Pin<Box<dyn Future<Output = Result<T, Error>>>>;
32
33pub enum WriteOutcome {
34  Partial { nwritten: usize, view: BufView },
35  Full { nwritten: usize },
36}
37
38impl WriteOutcome {
39  pub fn nwritten(&self) -> usize {
40    match self {
41      WriteOutcome::Partial { nwritten, .. } => *nwritten,
42      WriteOutcome::Full { nwritten } => *nwritten,
43    }
44  }
45}