Undo the getters change.

The getters were a good idea, but if we are going to support editing later, we will need to expose the fields or write A LOT of boiler-plate. The getters also would prevent people from moving values out of the AST without even more boiler-plate. It is simply not worth it at this stage, so we will need to tolerate frequently changing semver versions as the public interface changes since *every* field in the AST is public.
This commit is contained in:
Tom Alexander 2023-09-29 21:14:55 -04:00
parent d1dac0b8de
commit 3fb2b5d31c
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
6 changed files with 20 additions and 59 deletions

View File

@ -439,10 +439,13 @@ pub fn compare_document<'s>(
}
// TODO: Compare :path
// :path is a quoted string to the absolute path of the document.
let document_path = get_property_quoted_string(emacs, ":path")?;
// Compare category
// :CATEGORY is specified either from "#+CATEGORY:" or it is the file name without the ".org" extension.
let category = get_property_quoted_string(emacs, ":CATEGORY")?;
match (category.as_ref(), rust.category) {
match (category.as_ref(), rust.category.as_ref()) {
(None, None) => {}
(None, Some(_)) | (Some(_), None) => {
this_status = DiffStatus::Bad;

View File

@ -149,6 +149,7 @@ fn _document<'b, 'g, 'r, 's>(
Document {
source: source.into(),
category: None,
path: None,
zeroth_section,
children,
},

View File

@ -1,5 +1,5 @@
use super::macros::ref_getter;
use super::macros::simple_getter;
use std::path::PathBuf;
use super::Element;
use super::GetStandardProperties;
use super::Object;
@ -10,10 +10,11 @@ pub type HeadlineLevel = u16;
#[derive(Debug)]
pub struct Document<'s> {
pub(crate) source: &'s str,
pub(crate) category: Option<&'s str>,
pub(crate) zeroth_section: Option<Section<'s>>,
pub(crate) children: Vec<Heading<'s>>,
pub source: &'s str,
pub category: Option<String>,
pub path: Option<PathBuf>,
pub zeroth_section: Option<Section<'s>>,
pub children: Vec<Heading<'s>>,
}
#[derive(Debug)]
@ -73,9 +74,3 @@ impl<'s> StandardProperties<'s> for Heading<'s> {
self.source
}
}
impl<'s> Document<'s> {
simple_getter!(get_category, category, Option<&'s str>);
ref_getter!(get_zeroth_section, zeroth_section, Option<Section<'s>>);
ref_getter!(get_children, children, Vec<Heading<'s>>);
}

View File

@ -1,7 +1,5 @@
use super::element::Element;
use super::lesser_element::TableCell;
use super::macros::ref_getter;
use super::macros::simple_getter;
use super::Keyword;
use super::Object;
use super::StandardProperties;
@ -25,14 +23,14 @@ pub type IndentationLevel = u16;
#[derive(Debug)]
pub struct PlainListItem<'s> {
pub(crate) source: &'s str,
pub(crate) indentation: IndentationLevel,
pub(crate) bullet: &'s str,
pub(crate) counter: Option<PlainListItemCounter>,
pub(crate) checkbox: Option<(CheckboxType, &'s str)>,
pub(crate) tag: Vec<Object<'s>>,
pub(crate) pre_blank: PlainListItemPreBlank,
pub(crate) children: Vec<Element<'s>>,
pub source: &'s str,
pub indentation: IndentationLevel,
pub bullet: &'s str,
pub counter: Option<PlainListItemCounter>,
pub checkbox: Option<(CheckboxType, &'s str)>,
pub tag: Vec<Object<'s>>,
pub pre_blank: PlainListItemPreBlank,
pub children: Vec<Element<'s>>,
}
pub type PlainListItemCounter = u16;
@ -161,20 +159,6 @@ impl<'s> StandardProperties<'s> for TableRow<'s> {
}
impl<'s> PlainListItem<'s> {
simple_getter!(get_indentation_level, indentation, IndentationLevel);
simple_getter!(
/// Get the bullet
///
/// Example output: "1. "
get_bullet,
bullet,
&'s str
);
simple_getter!(get_counter, counter, Option<PlainListItemCounter>);
simple_getter!(get_pre_blank, pre_blank, PlainListItemPreBlank);
ref_getter!(get_tag, tag, Vec<Object<'s>>);
ref_getter!(get_children, children, Vec<Element<'s>>);
pub fn get_checkbox(&self) -> Option<&'s str> {
self.checkbox.as_ref().map(|(_, checkbox)| *checkbox)
}

View File

@ -1,21 +0,0 @@
// TODO: Would be nice if I didn't have to specify a function name but it looks like concat_idents!() cannot be used to create an ident.
// TODO: Find out if proc macros could do this easier (for example, parsing out the field type)
macro_rules! simple_getter {
($(#[$meta:meta])* $funcname: ident, $field:ident, $fieldtype:ty) => {
$(#[$meta])*
pub fn $funcname(&self) -> $fieldtype {
self.$field
}
};
}
pub(crate) use simple_getter;
macro_rules! ref_getter {
($(#[$meta:meta])* $funcname: ident, $field:ident, $fieldtype:ty) => {
$(#[$meta])*
pub fn $funcname(&self) -> &$fieldtype {
&self.$field
}
};
}
pub(crate) use ref_getter;

View File

@ -3,7 +3,6 @@ mod element;
mod get_standard_properties;
mod greater_element;
mod lesser_element;
mod macros;
mod object;
mod source;
mod standard_properties;