Skip to content

Commit

Permalink
Some cleanups coming out of clippy
Browse files Browse the repository at this point in the history
textdump loader is thread-bound now, so doesn't need to be Arc. Rc is
good enough.
  • Loading branch information
rdaum committed Jan 27, 2024
1 parent 1046a72 commit 9b9d7bd
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions crates/db/src/db_loader_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use moor_values::var::Var;
use crate::db_worldstate::DbTxWorldState;
use crate::loader::LoaderInterface;

/// A loader client which uses a database transaction to load the world state.
impl LoaderInterface for DbTxWorldState {
fn create_object(
&self,
Expand Down
3 changes: 2 additions & 1 deletion crates/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// this program. If not, see <https://www.gnu.org/licenses/>.
//

use std::rc::Rc;
use std::sync::Arc;

use moor_values::model::WorldStateError;
Expand All @@ -38,7 +39,7 @@ pub struct DatabaseBuilder {
}

pub trait Database {
fn loader_client(self: Arc<Self>) -> Result<Arc<dyn LoaderInterface>, WorldStateError>;
fn loader_client(self: Arc<Self>) -> Result<Rc<dyn LoaderInterface>, WorldStateError>;
fn world_state_source(self: Arc<Self>) -> Result<Arc<dyn WorldStateSource>, WorldStateError>;
}

Expand Down
5 changes: 3 additions & 2 deletions crates/db/src/odb/rb_worldstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use std::collections::{HashMap, HashSet, VecDeque};
use std::path::PathBuf;
use std::rc::Rc;
use std::sync::Arc;

use strum::{EnumCount, IntoEnumIterator};
Expand Down Expand Up @@ -1096,9 +1097,9 @@ impl RelBoxTransaction {
}

impl Database for RelBoxWorldState {
fn loader_client(self: Arc<Self>) -> Result<Arc<dyn LoaderInterface>, WorldStateError> {
fn loader_client(self: Arc<Self>) -> Result<Rc<dyn LoaderInterface>, WorldStateError> {
let tx = RelBoxTransaction::new(self.db.clone());
Ok(Arc::new(DbTxWorldState { tx: Box::new(tx) }))
Ok(Rc::new(DbTxWorldState { tx: Box::new(tx) }))
}

fn world_state_source(self: Arc<Self>) -> Result<Arc<dyn WorldStateSource>, WorldStateError> {
Expand Down
2 changes: 1 addition & 1 deletion crates/db/src/rdb/paging/pager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl Pager {
let bid = inner
.page_table
.get(&page_id)
.ok_or_else(|| PagerError::InvalidPage)?;
.ok_or(PagerError::InvalidPage)?;
inner.pool.resolve_ptr(*bid)
}

Expand Down
5 changes: 3 additions & 2 deletions crates/kernel/src/textdump/load_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::fs::File;
use std::io;
use std::io::BufReader;
use std::path::PathBuf;
use std::rc::Rc;
use std::sync::Arc;

use metrics_macros::increment_counter;
Expand Down Expand Up @@ -90,7 +91,7 @@ fn cv_aspec_flag(flags: u16) -> ArgSpec {

#[tracing::instrument(skip(ldr))]
pub fn textdump_load(
ldr: Arc<dyn LoaderInterface>,
ldr: Rc<dyn LoaderInterface>,
path: PathBuf,
) -> Result<(), TextdumpReaderError> {
let textdump_import_span = span!(tracing::Level::INFO, "textdump_import");
Expand All @@ -105,7 +106,7 @@ pub fn textdump_load(
}

pub fn read_textdump<T: io::Read>(
loader: Arc<dyn LoaderInterface>,
loader: Rc<dyn LoaderInterface>,
reader: BufReader<T>,
) -> Result<Result<(), TextdumpReaderError>, TextdumpReaderError> {
let mut tdr = TextdumpReader::new(reader);
Expand Down
4 changes: 2 additions & 2 deletions crates/kernel/src/textdump/write_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//

use std::collections::BTreeMap;
use std::sync::Arc;
use std::rc::Rc;

use moor_compiler::Program;
use moor_db::loader::LoaderInterface;
Expand Down Expand Up @@ -59,7 +59,7 @@ fn cv_arg(flags: BitEnum<VerbFlag>, arg: VerbArgsSpec) -> (u16, i16) {

/// Take a transaction, and scan the relations and build a Textdump representing a snapshot of the world as it
/// exists in the transaction.
pub fn make_textdump(tx: Arc<dyn LoaderInterface>, version: Option<&str>) -> Textdump {
pub fn make_textdump(tx: Rc<dyn LoaderInterface>, version: Option<&str>) -> Textdump {
// To create the objects list, we need to scan all objects.
// For now, the expectation would be we can simply iterate from 0 to max object, checking validity of each
// object, and then adding it to the list.
Expand Down

0 comments on commit 9b9d7bd

Please sign in to comment.