Skip to content

Commit ff5f30b

Browse files
committed
Add RealContext
1 parent 617fd59 commit ff5f30b

4 files changed

Lines changed: 132 additions & 1 deletion

File tree

‎src/lib.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33

44
mod context;
55
mod drain;
6+
mod nix_cli;
67
mod protocol;
78
mod push;
9+
mod real_cache;
10+
mod real_context;
811
mod start;
912
mod tokio;
1013

11-
type AuthToken = ();
14+
type AuthToken = String;
1215

1316
#[derive(Debug, clap::Subcommand)]
1417
pub enum Command {

‎src/nix_cli.rs‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use core::convert::Infallible;
2+
3+
use bytes::Bytes;
4+
use nix_types::{NarInfo, NixStorePath};
5+
use smol_str::SmolStr;
6+
7+
use crate::context;
8+
use crate::protocol::StoreDir;
9+
10+
pub(crate) struct NixCli {}
11+
12+
impl context::Nix for NixCli {
13+
type Error = Infallible;
14+
15+
async fn nar(
16+
&self,
17+
_store_path: &NixStorePath<StoreDir>,
18+
) -> Result<Bytes, Self::Error> {
19+
todo!()
20+
}
21+
22+
async fn narinfo(
23+
&self,
24+
_store_path: &NixStorePath<StoreDir>,
25+
) -> Result<NarInfo<SmolStr, StoreDir>, Self::Error> {
26+
todo!()
27+
}
28+
29+
async fn store_closure(
30+
&self,
31+
_store_path: &NixStorePath<StoreDir>,
32+
) -> Result<impl futures::Stream<Item = NixStorePath<StoreDir>>, Self::Error>
33+
{
34+
Ok(futures::stream::pending())
35+
}
36+
}

‎src/real_cache.rs‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use core::convert::Infallible;
2+
use core::fmt;
3+
4+
use bytes::Bytes;
5+
use nix_types::{NarFileName, NarInfo, NarInfoFileName};
6+
7+
use crate::context;
8+
use crate::protocol::StoreDir;
9+
10+
pub(crate) struct RealCache {}
11+
12+
impl context::Cache for RealCache {
13+
type Error = Infallible;
14+
15+
async fn has_nar(
16+
&self,
17+
_nar_filename: &NarFileName,
18+
) -> Result<bool, Self::Error> {
19+
todo!()
20+
}
21+
22+
async fn has_narinfo(
23+
&self,
24+
_narinfo_filename: &NarInfoFileName,
25+
) -> Result<bool, Self::Error> {
26+
todo!()
27+
}
28+
29+
async fn write_nar(&self, _nar_bytes: Bytes) -> Result<(), Self::Error> {
30+
todo!()
31+
}
32+
33+
async fn write_narinfo(
34+
&self,
35+
_narinfo: NarInfo<impl fmt::Display, StoreDir>,
36+
) -> Result<(), Self::Error> {
37+
todo!()
38+
}
39+
}

‎src/real_context.rs‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
use core::fmt;
2+
3+
use nix_types::{CacheName, UserName};
4+
5+
use crate::nix_cli::NixCli;
6+
use crate::real_cache::RealCache;
7+
use crate::tokio::TokioSpawner;
8+
use crate::{AuthToken, context};
9+
10+
pub(crate) struct RealContext {
11+
spawner: TokioSpawner,
12+
}
13+
14+
#[derive(Debug)]
15+
pub(crate) enum CacheError {}
16+
17+
impl RealContext {
18+
pub(crate) fn new(spawner: TokioSpawner) -> Self {
19+
Self { spawner }
20+
}
21+
}
22+
23+
impl context::Context for RealContext {
24+
type Cache = RealCache;
25+
type Nix = NixCli;
26+
type Spawner = TokioSpawner;
27+
type CacheError = CacheError;
28+
29+
async fn cache(
30+
&mut self,
31+
_owner: UserName,
32+
_name: CacheName,
33+
_auth: AuthToken,
34+
) -> Result<Self::Cache, Self::CacheError> {
35+
todo!()
36+
}
37+
38+
fn nix(&self) -> &Self::Nix {
39+
&NixCli {}
40+
}
41+
42+
fn spawner(&self) -> &Self::Spawner {
43+
&self.spawner
44+
}
45+
}
46+
47+
impl fmt::Display for CacheError {
48+
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
49+
match *self {}
50+
}
51+
}
52+
53+
impl core::error::Error for CacheError {}

0 commit comments

Comments
 (0)