acton_core/message/message_address.rs
1/*
2 * Copyright (c) 2024. Govcraft
3 *
4 * Licensed under either of
5 * * Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8 * * MIT license: http://opensource.org/licenses/MIT
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the applicable License for the specific language governing permissions and
14 * limitations under that License.
15 */
16
17use acton_ern::prelude::*;
18use derive_new::new;
19
20use crate::common::Outbox;
21
22/// Message address with a sender id
23#[derive(new, Clone, Debug)]
24pub struct MessageAddress {
25 pub(crate) address: Outbox,
26 pub(crate) sender: Ern,
27}
28
29impl MessageAddress {
30 /// get address owner
31 pub fn name(&self) -> &str {
32 self.sender.root.as_str()
33 }
34}
35
36impl Default for MessageAddress {
37 fn default() -> Self {
38 let (outbox, _) = tokio::sync::mpsc::channel(1);
39 Self::new(outbox, Ern::default())
40 }
41}
42
43// write unit tests
44#[cfg(test)]
45mod tests {
46 use super::*;
47
48 #[test]
49 fn test_return_address() {
50 let return_address = MessageAddress::default();
51 assert!(return_address.address.is_closed());
52 }
53}