use qubit_fs::FileSystem;
use qubit_fs::path::Path;
use super::fs_rustdoc_support::rustdoc_provider;
use crate::qubit_fs_testkit::FileSystemFixture;
use crate::qubit_fs_testkit::FixtureError;
use crate::qubit_fs_testkit::FixtureResult;
pub struct RustdocSyncFixture {
file_system: FileSystem,
}
impl RustdocSyncFixture {
#[must_use]
pub fn new() -> Self {
Self {
file_system: rustdoc_provider::filesystem(),
}
}
}
impl FileSystemFixture for RustdocSyncFixture {
fn file_system(&self) -> &FileSystem {
&self.file_system
}
fn path(&self, relative: &str) -> FixtureResult<Path> {
Path::parse(&format!("/rustdoc/{relative}"))
.map_err(|error| FixtureError::with_source("invalid rustdoc path", error))
}
fn teardown(&self) -> FixtureResult<()> {
Ok(())
}
}
#[cfg(feature = "async")]
mod asynchronous {
use qubit_fs::AsyncFileSystem;
use qubit_fs::path::Path;
use super::super::fs_rustdoc_support::async_filesystem;
use crate::qubit_fs_testkit::AsyncFileSystemFixture;
use crate::qubit_fs_testkit::FixtureError;
use crate::qubit_fs_testkit::FixtureFuture;
use crate::qubit_fs_testkit::FixtureResult;
pub struct RustdocAsyncFixture {
file_system: AsyncFileSystem,
}
impl RustdocAsyncFixture {
#[must_use]
pub fn new() -> Self {
Self {
file_system: async_filesystem(),
}
}
}
impl AsyncFileSystemFixture for RustdocAsyncFixture {
fn file_system(&self) -> &AsyncFileSystem {
&self.file_system
}
fn path(&self, relative: &str) -> FixtureResult<Path> {
Path::parse(&format!("/rustdoc/{relative}"))
.map_err(|error| FixtureError::with_source("invalid rustdoc path", error))
}
fn teardown(&self) -> FixtureFuture<'_, ()> {
Box::pin(async { Ok(()) })
}
}
}
#[cfg(feature = "async")]
pub use asynchronous::RustdocAsyncFixture;