Packages
A Lisette project is made up of packages. A package is a directory, and its name is the namespace for all .lis files inside. In the example below, user.lis and post.lis belong to the models package.
Directorymy-app/
- lisette.toml project manifest
Directorysrc/
- main.lis entry point
Directorymodels/
modelspackage- user.lis
- post.lis
Directoryroutes/
routespackage- api.lis
Directoryadmin/
routes/adminpackage- panel.lis
Imports
Section titled “Imports”To import a package from your project:
import "models"package path, relative to project rootimport "routes/admin"nested package pathImported packages are namespaces:
import "models"
fn main() { let user = models.User { name: "Alice" } models.save(user)}To alias an imported package:
import m "models"
fn main() { let user = m.User { name: "Alice" } m.save(user)}Circular imports are disallowed.
Visibility
Section titled “Visibility”Definitions are visible to all other files in the same package. Use pub to expose them to other packages.
publicpub fn save(user: User) -> Result<(), error> { if !validate(user) { return Err(errors.New("email is required")) } Ok(())}
privatefn validate(user: User) -> bool { !user.email.is_empty()}A struct and its fields can be marked pub independently, and so can a method in an impl block:
pub struct User { pub name: string,public email: string,private}
impl User {public pub fn greet(self) -> string { "hi " + self.name }
private fn label(self) -> string { f"{self.name} <{self.email}>" }}Reaching a private field or method from another package is an error:
import "models"
fn handle(user: models.User) { let name = user.nameok, public field let greeting = user.greet()ok, public method let email = user.emailerror, private to models let label = user.label()error, private to models}Layout
Section titled “Layout”A binary project produces an executable. A project is a binary if it contains a main.lis. In a binary project, lis build compiles all .lis files under src/ and writes the executable to target/.lisette/bin/.
Directoryapp/
- lisette.toml
Directorysrc/
- main.lis entry point present
Directorymodels/
- user.lis
Directorytarget/
Directory.lisette/
Directorybin/
- app executable
A library project produces Go source code for Go users to import. A project is a library if it contains no main.lis. lis build mirrors src/ into target/, where each dir becomes a Go package and the files at the top become the lib’s root package.
Directorygeo/
- lisette.toml
Directorysrc/ entry point absent
- geo.lis
Directoryshapes/
- shapes.lis
Directorytarget/
- go.mod
- geo.go package
geo Directoryshapes/
- shapes.go package
shapes
- shapes.go package
Set name in lisette.toml to the Go module path Go users will import.
[project]name = "github.com/you/geo"version = "0.1.0"A Go user then imports it like any other module:
import ( "fmt"
"github.com/you/geo" "github.com/you/geo/shapes")
func main() { fmt.Println(geo.Area(), shapes.Perimeter())}