@@ -1,3 +1,14 @@
1+//! These are macros to make getting very nested fields in the `Editor` struct easier
2+//! These are macros instead of functions because functions will have to take `&mut self`
3+//! However, rust doesn't know that you only want a partial borrow instead of borrowing the
4+//! entire struct which `&mut self` says. This makes it impossible to do other mutable
5+//! stuff to the struct because it is already borrowed. Because macros are expanded,
6+//! this circumvents the problem because it is just like indexing fields by hand and then
7+//! putting a `&mut` in front of it. This way rust can see that we are only borrowing a
8+//! part of the struct and not the entire thing.
9+
10+/// Get the current view and document mutably as a tuple.
11+/// Returns `(&mut View, &mut Document)`
112#[macro_export]
213macro_rules! current {
314 ( $( $editor:ident ).+ ) => {{
@@ -7,6 +18,8 @@ macro_rules! current {
718 }};
819}
920
21+/// Get the current document mutably.
22+/// Returns `&mut Document`
1023#[macro_export]
1124macro_rules! doc_mut {
1225 ( $( $editor:ident ).+ ) => {{
@@ -14,6 +27,8 @@ macro_rules! doc_mut {
1427 }};
1528}
1629
30+/// Get the current view mutably.
31+/// Returns `&mut View`
1732#[macro_export]
1833macro_rules! view_mut {
1934 ( $( $editor:ident ).+ ) => {{
@@ -21,6 +36,8 @@ macro_rules! view_mut {
2136 }};
2237}
2338
39+/// Get the current view immutably
40+/// Returns `&View`
2441#[macro_export]
2542macro_rules! view {
2643 ( $( $editor:ident ).+ ) => {{