@@ -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.
10+/// Get the current view and document mutably as a tuple.
11+/// Returns `(&mut View, &mut Document)`
1#[macro_export]
12#[macro_export]
2macro_rules! current {
13macro_rules! current {
3 ( $( $editor:ident ).+ ) => {{
14 ( $( $editor:ident ).+ ) => {{
@@ -7,6 +18,8 @@ macro_rules! current {
21+/// Get the current document mutably.
22+/// Returns `&mut Document`
10#[macro_export]
23#[macro_export]
11macro_rules! doc_mut {
24macro_rules! doc_mut {
12 ( $( $editor:ident ).+ ) => {{
25 ( $( $editor:ident ).+ ) => {{
@@ -14,6 +27,8 @@ macro_rules! doc_mut {
30+/// Get the current view mutably.
31+/// Returns `&mut View`
17#[macro_export]
32#[macro_export]
18macro_rules! view_mut {
33macro_rules! view_mut {
19 ( $( $editor:ident ).+ ) => {{
34 ( $( $editor:ident ).+ ) => {{
@@ -21,6 +36,8 @@ macro_rules! view_mut {
39+/// Get the current view immutably
24#[macro_export]
41#[macro_export]
25macro_rules! view {
42macro_rules! view {
26 ( $( $editor:ident ).+ ) => {{
43 ( $( $editor:ident ).+ ) => {{