repo_path: rename value() to clearer as_str()

This commit is contained in:
Martin von Zweigbergk 2021-06-05 22:48:09 -07:00
parent fdeb499836
commit ac38c8b641
3 changed files with 9 additions and 9 deletions

View file

@ -21,7 +21,7 @@ pub struct RepoPathComponent {
} }
impl RepoPathComponent { impl RepoPathComponent {
pub fn value(&self) -> &str { pub fn as_str(&self) -> &str {
&self.value &self.value
} }
} }
@ -73,7 +73,7 @@ impl RepoPath {
pub fn to_internal_dir_string(&self) -> String { pub fn to_internal_dir_string(&self) -> String {
let mut result = String::new(); let mut result = String::new();
for component in &self.components { for component in &self.components {
result.push_str(component.value()); result.push_str(component.as_str());
result.push('/'); result.push('/');
} }
result result

View file

@ -126,14 +126,14 @@ impl Tree {
match path.split() { match path.split() {
Some((dir, basename)) => self Some((dir, basename)) => self
.sub_tree_recursive(dir.components()) .sub_tree_recursive(dir.components())
.and_then(|tree| tree.data.value(basename.value()).cloned()), .and_then(|tree| tree.data.value(basename.as_str()).cloned()),
None => Some(TreeValue::Tree(self.id.clone())), None => Some(TreeValue::Tree(self.id.clone())),
} }
} }
pub fn sub_tree(&self, name: &RepoPathComponent) -> Option<Tree> { pub fn sub_tree(&self, name: &RepoPathComponent) -> Option<Tree> {
self.data self.data
.value(name.value()) .value(name.as_str())
.and_then(|sub_tree| match sub_tree { .and_then(|sub_tree| match sub_tree {
TreeValue::Tree(sub_tree_id) => { TreeValue::Tree(sub_tree_id) => {
let subdir = self.dir.join(name); let subdir = self.dir.join(name);
@ -160,7 +160,7 @@ impl Tree {
data: self.data.clone(), data: self.data.clone(),
}) })
} else { } else {
match self.data.entry(components[0].value()) { match self.data.entry(components[0].as_str()) {
None => None, None => None,
Some(entry) => match entry.value() { Some(entry) => match entry.value() {
TreeValue::Tree(sub_tree_id) => { TreeValue::Tree(sub_tree_id) => {

View file

@ -68,10 +68,10 @@ impl TreeBuilder {
let tree = trees_to_write.get_mut(&dir).unwrap(); let tree = trees_to_write.get_mut(&dir).unwrap();
match file_override { match file_override {
Override::Replace(value) => { Override::Replace(value) => {
tree.set(basename.value().to_string(), value); tree.set(basename.as_str().to_string(), value);
} }
Override::Tombstone => { Override::Tombstone => {
tree.remove(basename.value()); tree.remove(basename.as_str());
} }
} }
} }
@ -95,10 +95,10 @@ impl TreeBuilder {
if let Some((parent, basename)) = dir.split() { if let Some((parent, basename)) = dir.split() {
let parent_tree = trees_to_write.get_mut(&parent).unwrap(); let parent_tree = trees_to_write.get_mut(&parent).unwrap();
if tree.is_empty() { if tree.is_empty() {
parent_tree.remove(basename.value()); parent_tree.remove(basename.as_str());
} else { } else {
let tree_id = store.write_tree(&dir, &tree).unwrap(); let tree_id = store.write_tree(&dir, &tree).unwrap();
parent_tree.set(basename.value().to_string(), TreeValue::Tree(tree_id)); parent_tree.set(basename.as_str().to_string(), TreeValue::Tree(tree_id));
} }
} else { } else {
// We're writing the root tree. Write it even if empty. Return its id. // We're writing the root tree. Write it even if empty. Return its id.