radicle: remove FetchResult associated type
The Handle trait defines a FetchResult associated type. This type is always instantiated to be the FetchResult enum in radicle::node. Remove the associated type to simplify the trait. Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
parent
06a92d52d9
commit
c0b92d25fb
|
|
@ -13,7 +13,7 @@ use serde_json as json;
|
||||||
|
|
||||||
use crate::identity::Id;
|
use crate::identity::Id;
|
||||||
use crate::node::NodeId;
|
use crate::node::NodeId;
|
||||||
use crate::node::{Command, CommandName, CommandResult, FetchResult};
|
use crate::node::{Command, CommandName, CommandResult};
|
||||||
use crate::runtime;
|
use crate::runtime;
|
||||||
|
|
||||||
#[derive(thiserror::Error, Debug)]
|
#[derive(thiserror::Error, Debug)]
|
||||||
|
|
@ -25,7 +25,7 @@ pub enum Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Listen for commands on the control socket, and process them.
|
/// Listen for commands on the control socket, and process them.
|
||||||
pub fn listen<H: Handle<Error = runtime::HandleError, FetchResult = FetchResult>>(
|
pub fn listen<H: Handle<Error = runtime::HandleError>>(
|
||||||
listener: UnixListener,
|
listener: UnixListener,
|
||||||
mut handle: H,
|
mut handle: H,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
|
@ -74,7 +74,7 @@ enum CommandError {
|
||||||
Shutdown,
|
Shutdown,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn command<H: Handle<Error = runtime::HandleError, FetchResult = FetchResult>>(
|
fn command<H: Handle<Error = runtime::HandleError>>(
|
||||||
stream: &UnixStream,
|
stream: &UnixStream,
|
||||||
handle: &mut H,
|
handle: &mut H,
|
||||||
) -> Result<(), CommandError> {
|
) -> Result<(), CommandError> {
|
||||||
|
|
@ -199,7 +199,7 @@ fn command<H: Handle<Error = runtime::HandleError, FetchResult = FetchResult>>(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch<W: Write, H: Handle<Error = runtime::HandleError, FetchResult = FetchResult>>(
|
fn fetch<W: Write, H: Handle<Error = runtime::HandleError>>(
|
||||||
id: Id,
|
id: Id,
|
||||||
node: NodeId,
|
node: NodeId,
|
||||||
mut writer: W,
|
mut writer: W,
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,6 @@ impl<G: Signer + Ecdh + 'static> Handle<G> {
|
||||||
impl<G: Signer + Ecdh + 'static> radicle::node::Handle for Handle<G> {
|
impl<G: Signer + Ecdh + 'static> radicle::node::Handle for Handle<G> {
|
||||||
type Sessions = Sessions;
|
type Sessions = Sessions;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type FetchResult = FetchResult;
|
|
||||||
|
|
||||||
fn is_running(&self) -> bool {
|
fn is_running(&self) -> bool {
|
||||||
true
|
true
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ pub struct Handle {
|
||||||
impl radicle::node::Handle for Handle {
|
impl radicle::node::Handle for Handle {
|
||||||
type Error = HandleError;
|
type Error = HandleError;
|
||||||
type Sessions = service::Sessions;
|
type Sessions = service::Sessions;
|
||||||
type FetchResult = FetchResult;
|
|
||||||
|
|
||||||
fn is_running(&self) -> bool {
|
fn is_running(&self) -> bool {
|
||||||
true
|
true
|
||||||
|
|
|
||||||
|
|
@ -243,8 +243,6 @@ pub trait Handle {
|
||||||
type Sessions;
|
type Sessions;
|
||||||
/// The error returned by all methods.
|
/// The error returned by all methods.
|
||||||
type Error: std::error::Error + Send + Sync + 'static;
|
type Error: std::error::Error + Send + Sync + 'static;
|
||||||
/// Result of a fetch.
|
|
||||||
type FetchResult;
|
|
||||||
|
|
||||||
/// Check if the node is running. to a peer.
|
/// Check if the node is running. to a peer.
|
||||||
fn is_running(&self) -> bool;
|
fn is_running(&self) -> bool;
|
||||||
|
|
@ -253,7 +251,7 @@ pub trait Handle {
|
||||||
/// Lookup the seeds of a given repository in the routing table.
|
/// Lookup the seeds of a given repository in the routing table.
|
||||||
fn seeds(&mut self, id: Id) -> Result<Vec<NodeId>, Self::Error>;
|
fn seeds(&mut self, id: Id) -> Result<Vec<NodeId>, Self::Error>;
|
||||||
/// Fetch a repository from the network.
|
/// Fetch a repository from the network.
|
||||||
fn fetch(&mut self, id: Id, from: NodeId) -> Result<Self::FetchResult, Self::Error>;
|
fn fetch(&mut self, id: Id, from: NodeId) -> Result<FetchResult, Self::Error>;
|
||||||
/// Start tracking the given project. Doesn't do anything if the project is already
|
/// Start tracking the given project. Doesn't do anything if the project is already
|
||||||
/// tracked.
|
/// tracked.
|
||||||
fn track_repo(&mut self, id: Id) -> Result<bool, Self::Error>;
|
fn track_repo(&mut self, id: Id) -> Result<bool, Self::Error>;
|
||||||
|
|
@ -319,7 +317,6 @@ impl Node {
|
||||||
impl Handle for Node {
|
impl Handle for Node {
|
||||||
type Sessions = ();
|
type Sessions = ();
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type FetchResult = FetchResult;
|
|
||||||
|
|
||||||
fn is_running(&self) -> bool {
|
fn is_running(&self) -> bool {
|
||||||
let Ok(mut lines) = self.call::<&str, CommandResult>(CommandName::Status, []) else {
|
let Ok(mut lines) = self.call::<&str, CommandResult>(CommandName::Status, []) else {
|
||||||
|
|
@ -346,7 +343,7 @@ impl Handle for Node {
|
||||||
Ok(seeds)
|
Ok(seeds)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch(&mut self, id: Id, from: NodeId) -> Result<Self::FetchResult, Error> {
|
fn fetch(&mut self, id: Id, from: NodeId) -> Result<FetchResult, Error> {
|
||||||
let result = self
|
let result = self
|
||||||
.call(CommandName::Fetch, [id.urn(), from.to_human()])?
|
.call(CommandName::Fetch, [id.urn(), from.to_human()])?
|
||||||
.next()
|
.next()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue