databoard 0.3.1

Provides a hierarchical key-value-store
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
// Copyright © 2025 Stephan Kunz
//! Implements the [`Databoard`].
#![allow(unused)]
#![allow(clippy::missing_const_for_fn)]
#![allow(clippy::unnecessary_wraps)]
#![allow(clippy::unused_self)]
#![allow(clippy::extra_unused_type_parameters)]
#![allow(clippy::option_if_let_else)]

#[cfg(feature = "std")]
extern crate std;

use core::{any::Any, ops::Deref};

use alloc::sync::Arc;

use spin::RwLock;

use crate::{
	Error, RemappingList, RemappingTarget, check_local_key, check_top_level_key,
	database::Database,
	entry::{EntryPtr, EntryReadGuard, EntryWriteGuard},
	error::Result,
};

/// A thread safe data board.
pub struct Databoard(Arc<DataboardInner>);

impl Clone for Databoard {
	fn clone(&self) -> Self {
		Self(self.0.clone())
	}
}

impl core::fmt::Debug for Databoard {
	fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
		write!(f, "Databoard {{ ")?;
		write!(f, "autoremap: {:?}", &self.0.autoremap)?;
		write!(f, ", {:?}", &*self.0.database.read())?;
		write!(f, ", {:?}", &self.0.remappings)?;
		write!(f, ", parent: ")?;
		if let Some(parent) = &self.0.parent {
			write!(f, "{parent:?}",)
		} else {
			write!(f, "None")
		}?;
		write!(f, " }}")
	}
}

impl Deref for Databoard {
	type Target = DataboardInner;

	fn deref(&self) -> &Self::Target {
		&self.0
	}
}

impl Default for Databoard {
	fn default() -> Self {
		Self(Arc::new(DataboardInner {
			database: RwLock::new(Database::default()),
			parent: None,
			remappings: RemappingList::default(),
			autoremap: false,
		}))
	}
}

impl Databoard {
	/// Creates a [`Databoard`].
	#[must_use]
	pub fn new() -> Self {
		Self::default()
	}

	/// Creates a [`Databoard`] with given parameters.
	#[must_use]
	pub fn with(parent: Option<Self>, remappings: Option<RemappingList>, autoremap: bool) -> Self {
		let remappings = remappings.unwrap_or_default();
		let database = RwLock::new(Database::default());
		Self(Arc::new(DataboardInner {
			database,
			parent,
			remappings,
			autoremap,
		}))
	}

	/// Creates a [`Databoard`] using the given parent.
	/// The parents entries are automatically remapped into the new databoard.
	#[must_use]
	pub fn with_parent(parent: Self) -> Self {
		let database = RwLock::new(Database::default());
		Self(Arc::new(DataboardInner {
			database,
			parent: Some(parent),
			remappings: RemappingList::default(),
			autoremap: true,
		}))
	}
}

/// Implements a hierarchical databoard.
#[derive(Default)]
pub struct DataboardInner {
	/// database of this `Databoard`.
	/// It is behind an `RwLock` to protect against data races.
	database: RwLock<Database>,
	/// An optional reference to a parent `Databoard`.
	parent: Option<Databoard>,
	/// Manual remapping rules from this `Databoard` to the parent.
	remappings: RemappingList,
	/// Whether to use automatic remapping to parents content.
	autoremap: bool,
}

impl DataboardInner {
	/// Returns `true` if a certain `key` is available, otherwise `false`.
	#[must_use]
	pub fn contains_key(&self, key: &str) -> bool {
		match check_top_level_key(key) {
			Ok(stripped_key) => self.root().contains_key(stripped_key),
			Err(original_key) => match check_local_key(original_key) {
				Ok(local_key) => self.database.read().contains_key(local_key),
				Err(original_key) => match self.remappings.find(original_key) {
					RemappingTarget::BoardPointer(remapped_key) => {
						if let Some(parent) = &self.parent {
							parent.contains_key(&remapped_key)
						} else {
							false
						}
					}
					RemappingTarget::LocalPointer(remapped_key) => self.database.read().contains_key(&remapped_key),
					RemappingTarget::RootPointer(remapped_key) => self.root().contains_key(&remapped_key),
					RemappingTarget::StringAssignment(_) => false,
					RemappingTarget::None(original_key) => {
						if self.autoremap
							&& let Some(parent) = &self.parent
						{
							parent.contains_key(&original_key)
						} else {
							self.database.read().contains_key(&original_key)
						}
					}
				},
			},
		}
	}

	/// Returns a result of `true` if a certain `key` is available, otherwise a result of `false`.
	/// # Errors
	/// - [`Error::NoParent`]  if `key` is remapped to a parent without having a parent.
	/// - [`Error::WrongType`] if the entry has not the expected type `T`.
	pub fn contains<T: Any + Send + Sync>(&self, key: &str) -> Result<bool> {
		match check_top_level_key(key) {
			Ok(stripped_key) => self.root().contains::<T>(stripped_key),
			Err(original_key) => match check_local_key(original_key) {
				Ok(local_key) => self.database.read().contains::<T>(local_key),
				Err(original_key) => match self.remappings.find(original_key) {
					RemappingTarget::BoardPointer(remapped_key) => self.parent.as_ref().map_or_else(
						|| {
							Err(Error::NoParent {
								key: key.into(),
								remapped: remapped_key.clone(),
							})
						},
						|parent| parent.contains::<T>(&remapped_key),
					),
					RemappingTarget::LocalPointer(remapped_key) => self.database.read().contains::<T>(&remapped_key),
					RemappingTarget::RootPointer(remapped_key) => self.root().contains::<T>(&remapped_key),
					RemappingTarget::StringAssignment(assignment) => Err(Error::Assignment {
						key: original_key.into(),
						value: assignment,
					}),
					RemappingTarget::None(original_key) => {
						if self.autoremap
							&& let Some(parent) = &self.parent
						{
							parent.contains::<T>(&original_key)
						} else {
							self.database.read().contains::<T>(&original_key)
						}
					}
				},
			},
		}
	}

	/// Prints the content of the [`Databoard`] for debugging purpose.
	#[cfg(feature = "std")]
	pub fn debug_message(&self) {
		let _ = self.parent;
		std::println!("not yet implemented");
	}

	/// Returns the value of type `T` stored under `key` and deletes it from database.
	/// # Errors
	/// - [`Error::Assignment`] if the remapping contains an assignment of a `str` value.
	/// - [`Error::NoParent`]   if `key` is remapped to a parent without having a parent.
	/// - [`Error::NotFound`]   if `key` is not contained.
	/// - [`Error::WrongType`]  if the entry has not the expected type `T`.
	pub fn delete<T: Any + Send + Sync>(&self, key: &str) -> Result<T> {
		match check_top_level_key(key) {
			Ok(stripped_key) => self.root().delete(stripped_key),
			Err(original_key) => match check_local_key(original_key) {
				Ok(local_key) => self.database.write().delete(local_key),
				Err(original_key) => match self.remappings.find(original_key) {
					RemappingTarget::BoardPointer(remapped_key) => self.parent.as_ref().map_or_else(
						|| {
							Err(Error::NoParent {
								key: key.into(),
								remapped: remapped_key.clone(),
							})
						},
						|parent| parent.delete(&remapped_key),
					),
					RemappingTarget::LocalPointer(remapped_key) => self.database.write().delete(&remapped_key),
					RemappingTarget::RootPointer(remapped_key) => self.root().delete(&remapped_key),
					RemappingTarget::StringAssignment(assignment) => Err(Error::Assignment {
						key: original_key.into(),
						value: assignment,
					}),
					RemappingTarget::None(original_key) => {
						if self.autoremap
							&& let Some(parent) = &self.parent
						{
							parent.delete(&original_key)
						} else {
							self.database.write().delete(&original_key)
						}
					}
				},
			},
		}
	}

	/// Returns a clone of the [`EntryPtr`] stored under `key`.
	/// # Errors
	/// - [`Error::Assignment`] if the remapping contains an assignment of a `str` value.
	/// - [`Error::NoParent`]   if `key` is remapped to a parent without having a parent.
	/// - [`Error::NotFound`]   if `key` is not contained.
	pub fn entry(&self, key: &str) -> Result<EntryPtr> {
		match check_top_level_key(key) {
			Ok(stripped_key) => self.root().entry(stripped_key),
			Err(original_key) => match check_local_key(original_key) {
				Ok(local_key) => self.database.read().entry(local_key),
				Err(original_key) => match self.remappings.find(original_key) {
					RemappingTarget::BoardPointer(remapped_key) => self.parent.as_ref().map_or_else(
						|| {
							Err(Error::NoParent {
								key: key.into(),
								remapped: remapped_key.clone(),
							})
						},
						|parent| parent.entry(&remapped_key),
					),
					RemappingTarget::LocalPointer(remapped_key) => self.database.read().entry(&remapped_key),
					RemappingTarget::RootPointer(remapped_key) => self.root().entry(&remapped_key),
					RemappingTarget::StringAssignment(assignment) => Err(Error::Assignment {
						key: original_key.into(),
						value: assignment,
					}),
					RemappingTarget::None(original_key) => {
						if self.autoremap
							&& let Some(parent) = &self.parent
						{
							parent.entry(&original_key)
						} else {
							self.database.read().entry(&original_key)
						}
					}
				},
			},
		}
	}

	/// Returns a copy of the value of type `T` stored under `key`.
	/// # Errors
	/// - [`Error::Assignment`] if the remapping contains an assignment of a `str` value.
	/// - [`Error::NoParent`]   if `key` is remapped to a parent without having a parent.
	/// - [`Error::NotFound`]   if `key` is not contained.
	/// - [`Error::WrongType`]  if the entry has not the expected type `T`.
	pub fn get<T: Any + Clone + Send + Sync>(&self, key: &str) -> Result<T> {
		match check_top_level_key(key) {
			Ok(stripped_key) => self.root().get(stripped_key),
			Err(original_key) => match check_local_key(original_key) {
				Ok(local_key) => self.database.read().read(local_key),
				Err(original_key) => match self.remappings.find(original_key) {
					RemappingTarget::BoardPointer(remapped_key) => self.parent.as_ref().map_or_else(
						|| {
							Err(Error::NoParent {
								key: key.into(),
								remapped: remapped_key.clone(),
							})
						},
						|parent| parent.get(&remapped_key),
					),
					RemappingTarget::LocalPointer(remapped_key) => self.database.read().read(&remapped_key),
					RemappingTarget::RootPointer(remapped_key) => self.root().get(&remapped_key),
					RemappingTarget::StringAssignment(assignment) => Err(Error::Assignment {
						key: original_key.into(),
						value: assignment,
					}),
					RemappingTarget::None(original_key) => {
						if self.autoremap
							&& let Some(parent) = &self.parent
						{
							parent.get(&original_key)
						} else {
							self.database.read().read(&original_key)
						}
					}
				},
			},
		}
	}

	/// Returns a read/write guard to the `T` of the `entry` stored under `key`.
	/// The entry is locked for read & write while this reference is held.
	/// Multiple changes during holding the reference are counted as a single change,
	/// so `sequence_id()`will only increase by 1.
	///
	/// You need to drop the received [`EntryWriteGuard`] before using `delete`, `get`, `set` or `sequence_id`.
	/// # Errors
	/// - [`Error::Assignment`] if the remapping contains an assignment of a `str` value.
	/// - [`Error::NoParent`]   if `key` is remapped to a parent without having a parent.
	/// - [`Error::NotFound`]   if `key` is not contained.
	/// - [`Error::WrongType`]  if the entry has not the expected type `T`.
	pub fn get_mut_ref<T: Any + Send + Sync>(&self, key: &str) -> Result<EntryWriteGuard<T>> {
		match check_top_level_key(key) {
			Ok(stripped_key) => self.root().get_mut_ref(stripped_key),
			Err(original_key) => match check_local_key(original_key) {
				Ok(local_key) => self.database.read().get_mut_ref(local_key),
				Err(original_key) => match self.remappings.find(original_key) {
					RemappingTarget::BoardPointer(remapped_key) => self.parent.as_ref().map_or_else(
						|| {
							Err(Error::NoParent {
								key: key.into(),
								remapped: remapped_key.clone(),
							})
						},
						|parent| parent.get_mut_ref(&remapped_key),
					),
					RemappingTarget::LocalPointer(remapped_key) => self.database.read().get_mut_ref(&remapped_key),
					RemappingTarget::RootPointer(remapped_key) => self.root().get_mut_ref(&remapped_key),
					RemappingTarget::StringAssignment(assignment) => Err(Error::Assignment {
						key: original_key.into(),
						value: assignment,
					}),
					RemappingTarget::None(original_key) => {
						if self.autoremap
							&& let Some(parent) = &self.parent
						{
							parent.get_mut_ref(&original_key)
						} else {
							self.database.read().get_mut_ref(&original_key)
						}
					}
				},
			},
		}
	}

	/// Returns a read guard to the `T` of the `entry` stored under `key`.
	/// The entry is locked for write while this reference is held.
	///
	/// You need to drop the received [`EntryReadGuard`] before using `delete` or `set`.
	/// # Errors
	/// - [`Error::Assignment`] if the remapping contains an assignment of a `str` value.
	/// - [`Error::NoParent`]   if `key` is remapped to a parent without having a parent.
	/// - [`Error::NotFound`]   if `key` is not contained.
	/// - [`Error::WrongType`]  if the entry has not the expected type `T`.
	pub fn get_ref<T: Any + Send + Sync>(&self, key: &str) -> Result<EntryReadGuard<T>> {
		match check_top_level_key(key) {
			Ok(stripped_key) => self.root().get_ref(stripped_key),
			Err(original_key) => match check_local_key(original_key) {
				Ok(local_key) => self.database.read().get_ref(local_key),
				Err(original_key) => match self.remappings.find(original_key) {
					RemappingTarget::BoardPointer(remapped_key) => self.parent.as_ref().map_or_else(
						|| {
							Err(Error::NoParent {
								key: key.into(),
								remapped: remapped_key.clone(),
							})
						},
						|parent| parent.get_ref(&remapped_key),
					),
					RemappingTarget::LocalPointer(remapped_key) => self.database.read().get_ref(&remapped_key),
					RemappingTarget::RootPointer(remapped_key) => self.root().get_ref(&remapped_key),
					RemappingTarget::StringAssignment(assignment) => Err(Error::Assignment {
						key: original_key.into(),
						value: assignment,
					}),
					RemappingTarget::None(original_key) => {
						if self.autoremap
							&& let Some(parent) = &self.parent
						{
							parent.get_ref(&original_key)
						} else {
							self.database.read().get_ref(&original_key)
						}
					}
				},
			},
		}
	}

	/// Returns a reference to the remappings, if there are any, otherwise `None`.
	pub fn remappings(&self) -> Option<&RemappingList> {
		if self.remappings.is_empty() {
			None
		} else {
			Some(&self.remappings)
		}
	}

	/// Returns a reference to the root [`Databoard`] of the hierarchy.
	fn root(&self) -> &Self {
		self.parent
			.as_ref()
			.map_or(self, |board| board.root())
	}

	// /// Read needed remapping information to parent.
	// fn remapping_info(&self, key: &str) -> (RemappingTarget, bool) {
	// 	let (remapped_key, has_remapping) = self
	// 		.remappings
	// 		.find(key)
	// 		.map_or_else(|| (key.into(), false), |remapped| (remapped, true));

	// 	(remapped_key, has_remapping)
	// }

	/// Returns the sequence id of an entry.
	/// The sequence id starts with '1' and is increased at every change of an entry.
	/// The sequence wraps around to '1' after reaching [`usize::MAX`] .
	/// # Errors
	/// - [`Error::Assignment`] if the remapping contains an assignment of a `str` value.
	/// - [`Error::NoParent`]   if `key` is remapped to a parent without having a parent.
	/// - [`Error::NotFound`]   if `key` is not contained.
	pub fn sequence_id(&self, key: &str) -> Result<usize> {
		match check_top_level_key(key) {
			Ok(stripped_key) => self.root().sequence_id(stripped_key),
			Err(original_key) => match check_local_key(original_key) {
				Ok(local_key) => self.database.read().sequence_id(local_key),
				Err(original_key) => match self.remappings.find(original_key) {
					RemappingTarget::BoardPointer(remapped_key) => self.parent.as_ref().map_or_else(
						|| {
							Err(Error::NoParent {
								key: key.into(),
								remapped: remapped_key.clone(),
							})
						},
						|parent| parent.sequence_id(&remapped_key),
					),
					RemappingTarget::LocalPointer(remapped_key) => self.database.read().sequence_id(&remapped_key),
					RemappingTarget::RootPointer(remapped_key) => self.root().sequence_id(&remapped_key),
					RemappingTarget::StringAssignment(assignment) => Err(Error::Assignment {
						key: original_key.into(),
						value: assignment,
					}),
					RemappingTarget::None(original_key) => {
						if self.autoremap
							&& let Some(parent) = &self.parent
						{
							parent.sequence_id(&original_key)
						} else {
							self.database.read().sequence_id(&original_key)
						}
					}
				},
			},
		}
	}

	/// Stores the value of type `T` under `key` and returns an eventually existing value of type `T`.
	/// # Errors
	/// - [`Error::Assignment`] if the remapping contains an assignment of a `str` value.
	/// - [`Error::NoParent`]   if `key` is remapped to a parent without having a parent.
	/// - [`Error::WrongType`]  if `key` already exists with a different type.
	pub fn set<T: Any + Send + Sync>(&self, key: &str, value: T) -> Result<Option<T>> {
		match check_top_level_key(key) {
			Ok(stripped_key) => self.root().set(stripped_key, value),
			Err(original_key) => match check_local_key(original_key) {
				Ok(local_key) => {
					// 'contains_key' needs original key because it also checks for local key
					if self.contains_key(key) {
						let old = self.database.read().update(local_key, value)?;
						Ok(Some(old))
					} else {
						self.database.write().create(local_key, value)?;
						Ok(None)
					}
				}
				Err(original_key) => match self.remappings.find(original_key) {
					RemappingTarget::BoardPointer(remapped_key) => self.parent.as_ref().map_or_else(
						|| {
							Err(Error::NoParent {
								key: original_key.into(),
								remapped: remapped_key.clone(),
							})
						},
						|parent| parent.set(&remapped_key, value),
					),
					RemappingTarget::LocalPointer(remapped_key) => {
						if self.contains_key(&remapped_key) {
							let old = self
								.database
								.read()
								.update(&remapped_key, value)?;
							Ok(Some(old))
						} else {
							self.database
								.write()
								.create(remapped_key, value)?;
							Ok(None)
						}
					}
					RemappingTarget::RootPointer(remapped_key) => self.root().set(&remapped_key, value),
					RemappingTarget::StringAssignment(assignment) => Err(Error::Assignment {
						key: original_key.into(),
						value: assignment,
					}),
					RemappingTarget::None(original_key) => {
						if self.autoremap
							&& let Some(parent) = &self.parent
						{
							parent.set(&original_key, value)
						} else if self.contains_key(&original_key) {
							let old = self
								.database
								.read()
								.update(&original_key, value)?;
							Ok(Some(old))
						} else {
							self.database
								.write()
								.create(original_key, value)?;
							Ok(None)
						}
					}
				},
			},
		}
	}

	/// Returns a read/write guard to the `T` of the `entry` stored under `key`.
	/// The entry is locked for read & write while this reference is held.
	/// Multiple changes during holding the reference are counted as a single change,
	/// so `sequence_id()`will only increase by 1.
	///
	/// You need to drop the received [`EntryWriteGuard`] before using `delete`, `get...`, `set` or `sequence_id`.
	/// # Errors
	/// - [`Error::Assignment`] if the remapping contains an assignment of a `str` value.
	/// - [`Error::IsLocked`]   if the entry is locked by someone else.
	/// - [`Error::NoParent`]   if `key` is remapped to a parent without having a parent.
	/// - [`Error::NotFound`]   if `key` is not contained.
	/// - [`Error::WrongType`]  if the entry has not the expected type `T`.
	pub fn try_get_mut_ref<T: Any + Send + Sync>(&self, key: &str) -> Result<EntryWriteGuard<T>> {
		match check_top_level_key(key) {
			Ok(stripped_key) => self.root().try_get_mut_ref(stripped_key),
			Err(original_key) => match check_local_key(original_key) {
				Ok(local_key) => self.database.read().try_get_mut_ref(local_key),
				Err(original_key) => match self.remappings.find(original_key) {
					RemappingTarget::BoardPointer(remapped_key) => self.parent.as_ref().map_or_else(
						|| {
							Err(Error::NoParent {
								key: key.into(),
								remapped: remapped_key.clone(),
							})
						},
						|parent| parent.try_get_mut_ref(&remapped_key),
					),
					RemappingTarget::LocalPointer(remapped_key) => self
						.database
						.read()
						.try_get_mut_ref(&remapped_key),
					RemappingTarget::RootPointer(remapped_key) => self.root().try_get_mut_ref(&remapped_key),
					RemappingTarget::StringAssignment(assignment) => Err(Error::Assignment {
						key: original_key.into(),
						value: assignment,
					}),
					RemappingTarget::None(original_key) => {
						if self.autoremap
							&& let Some(parent) = &self.parent
						{
							parent.try_get_mut_ref(&original_key)
						} else {
							self.database
								.read()
								.try_get_mut_ref(&original_key)
						}
					}
				},
			},
		}
	}

	/// Returns a read guard to the `T` of the `entry` stored under `key`.
	/// The entry is locked for write while this reference is held.
	///
	/// You need to drop the received [`EntryReadGuard`] before using `delete` or `set`.
	/// # Errors
	/// - [`Error::Assignment`] if the remapping contains an assignment of a `str` value.
	/// - [`Error::IsLocked`]   if the entry is locked by someone else.
	/// - [`Error::NoParent`]   if `key` is remapped to a parent without having a parent.
	/// - [`Error::NotFound`]   if `key` is not contained.
	/// - [`Error::WrongType`]  if the entry has not the expected type `T`.
	pub fn try_get_ref<T: Any + Send + Sync>(&self, key: &str) -> Result<EntryReadGuard<T>> {
		match check_top_level_key(key) {
			Ok(stripped_key) => self.root().try_get_ref(stripped_key),
			Err(original_key) => match check_local_key(original_key) {
				Ok(local_key) => self.database.read().try_get_ref(local_key),
				Err(original_key) => match self.remappings.find(original_key) {
					RemappingTarget::BoardPointer(remapped_key) => self.parent.as_ref().map_or_else(
						|| {
							Err(Error::NoParent {
								key: key.into(),
								remapped: remapped_key.clone(),
							})
						},
						|parent| parent.try_get_ref(&remapped_key),
					),
					RemappingTarget::LocalPointer(remapped_key) => self.database.read().try_get_ref(&remapped_key),
					RemappingTarget::RootPointer(remapped_key) => self.root().try_get_ref(&remapped_key),
					RemappingTarget::StringAssignment(assignment) => Err(Error::Assignment {
						key: original_key.into(),
						value: assignment,
					}),
					RemappingTarget::None(original_key) => {
						if self.autoremap
							&& let Some(parent) = &self.parent
						{
							parent.get_ref(&original_key)
						} else {
							self.database.read().try_get_ref(&original_key)
						}
					}
				},
			},
		}
	}
}

#[cfg(test)]
mod tests {
	use super::*;

	// check, that the auto traits are available
	const fn is_normal<T: Sized + Send + Sync>() {}

	#[test]
	const fn normal_types() {
		is_normal::<DataboardInner>();
		is_normal::<Databoard>();
	}
}