yash_semantics/
runtime.rs

1// This file is part of yash, an extended POSIX shell.
2// Copyright (C) 2025 WATANABE Yuki
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program.  If not, see <https://www.gnu.org/licenses/>.
16
17//! Definition of `Runtime`
18
19use std::fmt::Debug;
20use yash_env::system::resource::SetRlimit;
21use yash_env::system::{
22    CaughtSignals, Clock, Close, Dup, Exec, Exit, Fcntl, Fork, Fstat, GetPid, GetPw,
23    IsExecutableFile, Isatty, Open, Pipe, Read, Seek, Select, SendSignal, SetPgid, ShellPath,
24    Sigaction, Sigmask, Signals, TcSetPgrp, Wait, Write,
25};
26
27/// Runtime environment for executing shell commands
28///
29/// This trait combines various capabilities required for command execution and
30/// word expansion into a single trait. Since the implementation of command
31/// execution and word expansion is mutually recursive, any trait needed for any
32/// part of the implementation is transitively required by most of the
33/// implementation. Therefore, this trait serves as a convenient shorthand to
34/// express the required capabilities.
35pub trait Runtime:
36    CaughtSignals
37    + Clock
38    + Close
39    + Debug
40    + Dup
41    + Exec
42    + Exit
43    + Fcntl
44    + Fork
45    + Fstat
46    + GetPid
47    + GetPw
48    + IsExecutableFile
49    + Isatty
50    + Open
51    + Pipe
52    + Read
53    + Seek
54    + Select
55    + SendSignal
56    + SetPgid
57    + SetRlimit
58    + ShellPath
59    + Sigaction
60    + Sigmask
61    + Signals
62    + TcSetPgrp
63    + Wait
64    + Write
65{
66}
67
68/// Any type automatically implements `Runtime` if it implements all the
69/// supertraits of `Runtime`.
70impl<S> Runtime for S where
71    S: CaughtSignals
72        + Clock
73        + Close
74        + Debug
75        + Dup
76        + Exec
77        + Exit
78        + Fcntl
79        + Fork
80        + Fstat
81        + GetPid
82        + GetPw
83        + IsExecutableFile
84        + Isatty
85        + Open
86        + Pipe
87        + Read
88        + Seek
89        + Select
90        + SendSignal
91        + SetPgid
92        + SetRlimit
93        + ShellPath
94        + Sigaction
95        + Sigmask
96        + Signals
97        + TcSetPgrp
98        + Wait
99        + Write
100{
101}