next_web_dev/application/
next_application.rs1use std::ops::Deref;
2
3use hashbrown::HashMap;
4use next_web_core::context::{
5 application_args::ApplicationArgs, properties::ApplicationProperties,
6};
7
8use super::application::Application;
9use next_web_core::autoconfigure::context::server_properties::ServerProperties;
10
11#[derive(Default)]
12pub struct NextApplication<A: Application> {
13 application_properties: ApplicationProperties,
14 application_args: ApplicationArgs,
15 application: A,
16}
17
18impl<A: Application + Default> NextApplication<A> {
19 pub fn new() -> Self {
20 Self {
21 application_properties: ApplicationProperties::new(),
22 application_args: ApplicationArgs::default(),
23 application: A::default(),
24 }
25 }
26
27 pub fn application_properties(&self) -> &ApplicationProperties {
29 &self.application_properties
30 }
31
32 pub fn application_args(&self) -> &ApplicationArgs {
34 &self.application_args
35 }
36
37 pub fn application_name(&self) -> &str {
39 self.application_properties()
40 .next()
41 .appliation()
42 .map(|var| var.name())
43 .unwrap_or_default()
44 }
45
46 pub fn server_context_path(&mut self) -> Option<&str> {
48 self.server_properties().context_path()
49 }
50
51 pub fn server_port(&mut self) -> Option<u16> {
53 self.server_properties().port()
54 }
55
56 pub fn server_properties(&self) -> &ServerProperties {
58 self.application_properties().next().server()
59 }
60
61 pub fn application(&mut self) -> &mut A {
63 &mut self.application
64 }
65
66 pub fn set_application_properties(&mut self, application_properties: ApplicationProperties) {
68 self.application_properties = application_properties;
69 }
70
71 pub fn set_configure_mappping(&mut self, mapping: HashMap<String, serde_yaml::Value>) {
73 self.application_properties.set_mapping(mapping);
74 }
75}
76
77impl<A: Application> Deref for NextApplication<A> {
78 type Target = A;
79
80 fn deref(&self) -> &Self::Target {
81 &self.application
82 }
83}