Public view functions on the other hand are very common, since reading public storage does not require any state
modifications. These are essentially equivalent to a Solidity view function.
No compile time checks are performed on whether a function can be made view. If a function marked as view attempts
to modify state, that will result in runtime failures.
View functions cannot modify state in any way, including performing contract calls that would in turn modify state.
This makes them easy to reason about: they are simply 'pure' functions that return a value, and carry e.g. no reentrancy risk.
Use Cases
Only public and private functions can be view.
Private view functions are typically not very useful as they cannot emit nullifiers, which is often required when reading private state (e.g. from a crate::state_vars::private_mutable::PrivateMutable or crate::state_vars::private_set::PrivateSet state variable). They do however have their use cases, such as performing a crate::state_vars::delayed_public_mutable::DelayedPublicMutable read.
Public view functions on the other hand are very common, since reading public storage does not require any state modifications. These are essentially equivalent to a Solidity
viewfunction.Guarantees
view functions can only be called in a static execution context, which is typically achieved by calling the crate::contract_self::ContractSelf::view method on
self.No compile time checks are performed on whether a function can be made view. If a function marked as view attempts to modify state, that will result in runtime failures.