Radish alpha
r
rad:zwTxygwuz5LDGBq255RA2CbNGrz8
Radicle CI broker
Radicle
Git
refactor: CiEventSource gets a reference to a profile instead of owning it
Lars Wirzenius committed 2 months ago
commit a5842ff37d4a69eb4d31a39c358712dfed8ef376
parent f38a67b
2 files changed +8 -8
modified src/ci_event_source.rs
@@ -8,15 +8,15 @@ use crate::{
    node_event_source::{NodeEventError, NodeEventSource},
};

-
pub struct CiEventSource {
+
pub struct CiEventSource<'a> {
    source: NodeEventSource,
-
    profile: Profile,
+
    profile: &'a Profile,
}

-
impl CiEventSource {
-
    pub fn new(profile: Profile) -> Result<Self, CiEventSourceError> {
+
impl<'a> CiEventSource<'a> {
+
    pub fn new(profile: &'a Profile) -> Result<Self, CiEventSourceError> {
        let source = Self {
-
            source: NodeEventSource::new(&profile).map_err(CiEventSourceError::Subscribe)?,
+
            source: NodeEventSource::new(profile).map_err(CiEventSourceError::Subscribe)?,
            profile,
        };
        logger::ci_event_source_created(&source);
@@ -43,7 +43,7 @@ impl CiEventSource {
                Ok(None)
            }
            Ok(Some(event)) => {
-
                let ci_events = CiEvent::from_node_event(&event, &self.profile)
+
                let ci_events = CiEvent::from_node_event(&event, self.profile)
                    .map_err(CiEventSourceError::CiEvent)?;
                if !ci_events.is_empty() {
                    logger::ci_event_source_got_events(&ci_events);
@@ -54,7 +54,7 @@ impl CiEventSource {
    }
}

-
impl fmt::Debug for CiEventSource {
+
impl<'a> fmt::Debug for CiEventSource<'a> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "CiEventSource<path={:?}", self.source)
    }
modified src/queueadd.rs
@@ -43,7 +43,7 @@ impl QueueAdder {
    fn add_events(&self) -> Result<(), AdderError> {
        let profile = Profile::load().map_err(AdderError::profile)?;

-
        let mut source = CiEventSource::new(profile)?;
+
        let mut source = CiEventSource::new(&profile)?;

        // This loop ends when there's an error, e.g., failure to read an
        // event from the node.