rustic_core/backend/
stdin.rs1use std::{
2 io::{Stdin, stdin},
3 iter::{Once, once},
4 path::PathBuf,
5};
6
7use crate::{
8 backend::{ReadSource, ReadSourceEntry},
9 error::{ErrorKind, RusticError, RusticResult},
10};
11
12#[derive(Debug, Clone)]
14pub struct StdinSource {
15 path: PathBuf,
17}
18
19impl StdinSource {
20 pub const fn new(path: PathBuf) -> Self {
22 Self { path }
23 }
24}
25
26impl ReadSource for StdinSource {
27 type Open = Stdin;
29 type Iter = Once<RusticResult<ReadSourceEntry<Stdin>>>;
31
32 fn size(&self) -> RusticResult<Option<u64>> {
34 Ok(None)
35 }
36
37 fn entries(&self) -> Self::Iter {
39 let open = Some(stdin());
40 once(
41 ReadSourceEntry::from_path(self.path.clone(), open).map_err(|err| {
42 RusticError::with_source(
43 ErrorKind::Backend,
44 "Failed to create ReadSourceEntry from Stdin",
45 err,
46 )
47 }),
48 )
49 }
50}