跳到主要内容

DirBuilder

搜索

结构体 DirBuilder 

Source
pub struct DirBuilder { /* private fields */ }
展开描述

用于以各种方式创建目录的构建器。

This is a specialized version of std::fs::DirBuilder for usage on the Tokio 运行时。

实现§

Source§

impl DirBuilder

Source

pub fn new() -> Self

使用所有平台的默认模式/安全设置创建一个新的选项集合,并且不递归。

这是 std::fs::DirBuilder::new 的异步版本。

§示例
use tokio::fs::DirBuilder;

let builder = DirBuilder::new();
Source

pub fn recursive(&mut self, recursive: bool) -> &mut Self

指示是否递归地创建目录(包括所有父目录)。 不存在的父目录将使用相同的安全性和权限设置创建。

此选项默认为 false

这是 std::fs::DirBuilder::recursive 的异步版本。

§示例
use tokio::fs::DirBuilder;

let mut builder = DirBuilder::new();
builder.recursive(true);
Source

pub async fn create(&self, path: impl AsRef<Path>) -> Result<()>

使用配置的选项创建指定的目录。

如果目录已经存在(除非启用了递归模式), 则视为错误。

这是 std::fs::DirBuilder::create 的异步版本。

§Errors

在以下情况下将返回错误:

  • Path already points to an existing file.
  • Path already points to an existing directory and the mode is non-recursive.
  • The calling process doesn’t have permissions to create the directory or its missing parents.
  • Other I/O error occurred.
§示例
use tokio::fs::DirBuilder;
use std::io;

#[tokio::main]
async fn main() -> io::Result<()> {
    DirBuilder::new()
        .recursive(true)
        .create("/tmp/foo/bar/baz")
        .await?;

    Ok(())
}

Trait 实现§

Source§

impl Debug for DirBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

使用给定的格式化器格式化此值。 更多信息
Source§

impl Default for DirBuilder

Source§

fn default() -> DirBuilder

Returns the “default value” for a type. 更多信息

自动 Trait 实现§

Blanket 实现§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. 更多信息
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. 更多信息
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 更多信息
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

原样返回传入的参数。

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

调用 U::from(self)

也就是说,此转换的具体行为取决于 From<T> for U 的实现方式。

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

转换出错时返回的类型。
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

执行转换。
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

转换出错时返回的类型。
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

执行转换。